Module: Hypostasis::Document::Fields::ClassMethods
- Defined in:
- lib/hypostasis/document/fields.rb
Instance Method Summary collapse
- #create_accessors(name, options) ⇒ Object
- #field(name, options = {}) ⇒ Object
- #fields ⇒ Object
- #register_field(name) ⇒ Object
Instance Method Details
#create_accessors(name, options) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/hypostasis/document/fields.rb', line 24 def create_accessors(name, ) self.class_eval do define_method(name) { @fields[name.to_sym] || nil } define_method("#{name}=") {|value| @fields[name.to_sym] = value} end end |
#field(name, options = {}) ⇒ Object
6 7 8 9 |
# File 'lib/hypostasis/document/fields.rb', line 6 def field(name, = {}) register_field(name.to_sym) create_accessors(name.to_s, ) end |
#fields ⇒ Object
11 12 13 |
# File 'lib/hypostasis/document/fields.rb', line 11 def fields self.class_eval { class_variable_get(:@@fields) } end |
#register_field(name) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/hypostasis/document/fields.rb', line 15 def register_field(name) self.class_eval do class_variable_set(:@@fields, []) unless class_variable_defined?(:@@fields) registered_fields = class_variable_get(:@@fields) registered_fields << name.to_sym class_variable_set(:@@fields, registered_fields) end end |