Class: Craftbelt::Settings
- Inherits:
-
Object
- Object
- Craftbelt::Settings
- Defined in:
- lib/craftbelt/settings.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #field(name) ⇒ Object
-
#initialize(definitions, values = {}) ⇒ Settings
constructor
A new instance of Settings.
Constructor Details
#initialize(definitions, values = {}) ⇒ Settings
Returns a new instance of Settings.
7 8 9 10 |
# File 'lib/craftbelt/settings.rb', line 7 def initialize(definitions, values={}) @schema = Brock::Schema.new(definitions) @values = values end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/craftbelt/settings.rb', line 5 def schema @schema end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
5 6 7 |
# File 'lib/craftbelt/settings.rb', line 5 def values @values end |
Instance Method Details
#field(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/craftbelt/settings.rb', line 12 def field(name) field = schema.fields.find{|f| f.name.to_sym == name.to_sym } value = values[name] if value.nil? value = values[name.to_sym] end raise "Unknown field: #{name}" if field.nil? and value.nil? if field if value.nil? field.default else field.parse_param(value) end else value end end |