Module: Spree::Preferences::PreferableClassMethods
- Defined in:
- lib/spree/core/preferences/preferable_class_methods.rb
Instance Method Summary collapse
- #preference(name, type, *args) ⇒ Object
- #preference_default_getter_method(name) ⇒ Object
- #preference_deprecated_getter_method(name) ⇒ Object
- #preference_getter_method(name) ⇒ Object
- #preference_setter_method(name) ⇒ Object
- #preference_type_getter_method(name) ⇒ Object
Instance Method Details
#preference(name, type, *args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spree/core/preferences/preferable_class_methods.rb', line 3 def preference(name, type, *args) = args. .assert_valid_keys(:default, :deprecated) default = [:default] default = -> { [:default] } unless default.is_a?(Proc) deprecated = [:deprecated] # cache_key will be nil for new objects, then if we check if there # is a pending preference before going to default define_method preference_getter_method(name) do preferences.fetch(name) do default.call end end define_method preference_setter_method(name) do |value| value = convert_preference_value(value, type) preferences[name] = value ActiveSupport::Deprecation.warn("`#{name}` is deprecated. #{deprecated}") if deprecated # If this is an activerecord object, we need to inform # ActiveRecord::Dirty that this value has changed, since this is an # in-place update to the preferences hash. preferences_will_change! if respond_to?(:preferences_will_change!) end define_method preference_default_getter_method(name), &default define_method preference_type_getter_method(name) do type end define_method preference_deprecated_getter_method(name) do deprecated end end |
#preference_default_getter_method(name) ⇒ Object
49 50 51 |
# File 'lib/spree/core/preferences/preferable_class_methods.rb', line 49 def preference_default_getter_method(name) "preferred_#{name}_default".to_sym end |
#preference_deprecated_getter_method(name) ⇒ Object
53 54 55 |
# File 'lib/spree/core/preferences/preferable_class_methods.rb', line 53 def preference_deprecated_getter_method(name) "preferred_#{name}_deprecated".to_sym end |
#preference_getter_method(name) ⇒ Object
41 42 43 |
# File 'lib/spree/core/preferences/preferable_class_methods.rb', line 41 def preference_getter_method(name) "preferred_#{name}".to_sym end |
#preference_setter_method(name) ⇒ Object
45 46 47 |
# File 'lib/spree/core/preferences/preferable_class_methods.rb', line 45 def preference_setter_method(name) "preferred_#{name}=".to_sym end |
#preference_type_getter_method(name) ⇒ Object
57 58 59 |
# File 'lib/spree/core/preferences/preferable_class_methods.rb', line 57 def preference_type_getter_method(name) "preferred_#{name}_type".to_sym end |