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 which contain default values for each attribute.
-
#inherited(subclass) ⇒ Object
Inject our default values into subclasses.
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
Define attribute with specific type and default value for current class.
74 75 76 77 78 79 80 81 |
# File 'lib/shallow_attributes/class_methods.rb', line 74 def attribute(name, type, = {}) [:default] ||= [] if type == Array default_values[name] = .delete(:default) initialize_setter(name, type, ) initialize_getter(name) end |
#attributes ⇒ Hash
Returns all class attributes.
48 49 50 |
# File 'lib/shallow_attributes/class_methods.rb', line 48 def attributes default_values.keys end |
#default_values ⇒ Hash
Returns hash which contain 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 |