Module: ShallowAttributes::ClassMethods Abstract
- Defined in:
- lib/shallow_attributes/class_methods.rb
Overview
This module is abstract.
Abstract class for value classes. Provides some helper methods for working with class methods.
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ Object
Define attribute with specific type and default value for current class.
-
#attributes ⇒ Hash
Returns all class attributes.
-
#default_values ⇒ Hash
Returns hash that contains default values for each attribute.
-
#inherited(subclass) ⇒ Object
Inject our default values into subclasses.
-
#mandatory_attributes ⇒ Hash
Returns hash that contains mandatory attributes.
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
Define attribute with specific type and default value for current class.
86 87 88 89 90 91 92 93 94 |
# File 'lib/shallow_attributes/class_methods.rb', line 86 def attribute(name, type, = {}) [:default] ||= [] if type == Array default_values[name] = .delete(:default) mandatory_attributes[name] = .delete(:present) initialize_setter(name, type, ) initialize_getter(name) end |
#attributes ⇒ Hash
Returns all class attributes.
59 60 61 |
# File 'lib/shallow_attributes/class_methods.rb', line 59 def attributes default_values.keys end |
#default_values ⇒ Hash
Returns hash that contains default values for each attribute
29 30 31 |
# File 'lib/shallow_attributes/class_methods.rb', line 29 def default_values @default_values ||= {} end |
#inherited(subclass) ⇒ Object
Inject our default values into subclasses.
15 16 17 18 19 20 |
# File 'lib/shallow_attributes/class_methods.rb', line 15 def inherited(subclass) super if respond_to?(:default_values) subclass.default_values.merge!(default_values) end end |
#mandatory_attributes ⇒ Hash
Returns hash that contains mandatory attributes
40 41 42 |
# File 'lib/shallow_attributes/class_methods.rb', line 40 def mandatory_attributes @mandatory_attributes ||= {} end |