Module: Hattr::ClassMethods
- Defined in:
- lib/hattr/class_methods.rb
Constant Summary collapse
- GROUP_OPTIONS =
[:string_keys].freeze
- ATTR_OPTIONS =
[:type].freeze
- GROUP_DEFAULTS =
{ string_keys: false }.freeze
- ATTR_DEFAULTS =
{ type: String }.freeze
- OPTIONS_STORAGE_KEY =
:_hattr_options- ARRAY_DEFAULT =
- HASH_DEFAULT =
Instance Method Summary collapse
- #build_group_hash(spec, value) ⇒ Object
- #hattr(field, attribute, opts = {}) ⇒ Object
- #hattr_group(field, opts = {}) ⇒ Object
Instance Method Details
#build_group_hash(spec, value) ⇒ Object
27 28 29 |
# File 'lib/hattr/class_methods.rb', line 27 def build_group_hash(spec, value) HashBuilder.generate(spec, value) end |
#hattr(field, attribute, opts = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/hattr/class_methods.rb', line 20 def hattr(field, attribute, opts = {}) raise ArgumentError, "`#{OPTIONS_STORAGE_KEY}` is reserved" if attribute.to_sym == OPTIONS_STORAGE_KEY (opts, ATTR_OPTIONS) store_attribute(field, attribute, ATTR_DEFAULTS.merge(opts)) end |
#hattr_group(field, opts = {}) ⇒ Object
15 16 17 18 |
# File 'lib/hattr/class_methods.rb', line 15 def hattr_group(field, opts = {}) (opts, GROUP_OPTIONS) store_group(field, GROUP_DEFAULTS.merge(opts)) end |