Sha256: adf69fb7513953772066f48ab2287821666e0d938149720618337ba7d715b4e8

Contents?: true

Size: 499 Bytes

Versions: 6

Compression:

Stored size: 499 Bytes

Contents

module UserPreferences
  class Defaults
    def initialize(definitions)
      @definitions = definitions
    end

    def get(category = nil)
      if category
        category_defaults(category)
      else
        @definitions.inject({}) { |h, (k,v)| h[k.to_sym] = category_defaults(k); h }
      end
    end

    private

    def category_defaults(category)
      @definitions[category].inject({}) do |h, (k,v)|
        h[k.to_sym] = v.is_a?(Hash) ? v['default'] : v; h
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
user_preferences-1.0.2 lib/user_preferences/defaults.rb
user_preferences-1.0.1 lib/user_preferences/defaults.rb
user_preferences-1.0.0 lib/user_preferences/defaults.rb
user_preferences-0.0.3 lib/user_preferences/defaults.rb
user_preferences-0.0.2 lib/user_preferences/defaults.rb
user_preferences-0.0.1 lib/user_preferences/defaults.rb