Module: ActiveAny::Attribute::ClassMethods
- Defined in:
- lib/active_any/attribute.rb
Instance Method Summary collapse
- #attribute(name) ⇒ Object
- #attribute_names ⇒ Object
- #attributes(*names) ⇒ Object
- #define_reader_method(name) ⇒ Object
- #define_writer_method(name) ⇒ Object
- #has_attribute?(attribute) ⇒ Boolean
Instance Method Details
#attribute(name) ⇒ Object
48 49 50 51 52 |
# File 'lib/active_any/attribute.rb', line 48 def attribute(name) attribute_names << name.to_sym define_writer_method name define_reader_method name end |
#attribute_names ⇒ Object
54 55 56 |
# File 'lib/active_any/attribute.rb', line 54 def attribute_names @attribute_names ||= [] end |
#attributes(*names) ⇒ Object
44 45 46 |
# File 'lib/active_any/attribute.rb', line 44 def attributes(*names) names.each { |name| attribute name } end |
#define_reader_method(name) ⇒ Object
64 65 66 67 68 |
# File 'lib/active_any/attribute.rb', line 64 def define_reader_method(name) define_method name do attributes.fetch(name, nil) end end |
#define_writer_method(name) ⇒ Object
58 59 60 61 62 |
# File 'lib/active_any/attribute.rb', line 58 def define_writer_method(name) define_method "#{name}=" do |value| attributes[name] = value end end |
#has_attribute?(attribute) ⇒ Boolean
70 71 72 |
# File 'lib/active_any/attribute.rb', line 70 def has_attribute?(attribute) attribute_names.include?(attribute) end |