Class: Concerns::Addressable::Config
- Inherits:
-
Object
- Object
- Concerns::Addressable::Config
- Defined in:
- app/models/concerns/addressable/config.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #allowed?(field) ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #update(categories, default: nil) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
6 7 8 9 |
# File 'app/models/concerns/addressable/config.rb', line 6 def initialize @fields = [] @default = nil end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'app/models/concerns/addressable/config.rb', line 4 def default @default end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
4 5 6 |
# File 'app/models/concerns/addressable/config.rb', line 4 def fields @fields end |
Instance Method Details
#allowed?(field) ⇒ Boolean
28 29 30 |
# File 'app/models/concerns/addressable/config.rb', line 28 def allowed?(field) @fields.include?(field.to_sym) end |
#update(categories, default: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/concerns/addressable/config.rb', line 11 def update(categories, default: nil) unless categories.respond_to?(:each) && categories.any? raise 'Please provide an array with address categories' end @fields = categories.map(&:to_sym).uniq @default = @fields.first if default unless @fields.include?(default.to_sym) raise "You can't make '#{default.to_s}' the default address category because it's not in the list of categories" end @default = default.to_sym end end |