Module: Zenodo::Resources::Object::Attributes::ClassMethods
- Defined in:
- lib/zenodo/resources/object/attributes.rb
Instance Method Summary collapse
- #attribute(name, type = String) ⇒ Object (also: #has_many)
- #attributes ⇒ Object
-
#attributes_module ⇒ Module
Module holding all attribute accessors.
- #define_attribute_accessor(name, type = nil) ⇒ Object
Instance Method Details
#attribute(name, type = String) ⇒ Object Also known as: has_many
26 27 28 29 30 |
# File 'lib/zenodo/resources/object/attributes.rb', line 26 def attribute(name, type = String) attributes[name] = type define_attribute_accessor(name, type) end |
#attributes ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/zenodo/resources/object/attributes.rb', line 3 def attributes @attributes ||= begin if superclass.respond_to?(:attributes) superclass.attributes.dup else Hash.new { |hash, key| hash[key] = ::Object } end end end |
#attributes_module ⇒ Module
Returns module holding all attribute accessors.
15 16 17 |
# File 'lib/zenodo/resources/object/attributes.rb', line 15 def attributes_module @attributes_module ||= const_set(:AttributeMethods, Module.new) end |
#define_attribute_accessor(name, type = nil) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/zenodo/resources/object/attributes.rb', line 19 def define_attribute_accessor(name, type = nil) type ||= attributes[name.to_sym] || Object attributes_module.send(:define_method, name) do deserialize_attribute(name, type) end end |