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
44 45 46 47 48 |
# File 'lib/active_any/attribute.rb', line 44 def attribute(name) attribute_names << name.to_sym define_writer_method name define_reader_method name end |
#attribute_names ⇒ Object
50 51 52 |
# File 'lib/active_any/attribute.rb', line 50 def attribute_names @attribute_names ||= [] end |
#attributes(*names) ⇒ Object
40 41 42 |
# File 'lib/active_any/attribute.rb', line 40 def attributes(*names) names.each { |name| attribute name } end |
#define_reader_method(name) ⇒ Object
60 61 62 63 64 |
# File 'lib/active_any/attribute.rb', line 60 def define_reader_method(name) define_method name do attributes.fetch(name, nil) end end |
#define_writer_method(name) ⇒ Object
54 55 56 57 58 |
# File 'lib/active_any/attribute.rb', line 54 def define_writer_method(name) define_method "#{name}=" do |value| attributes[name] = value end end |
#has_attribute?(attribute) ⇒ Boolean
66 67 68 |
# File 'lib/active_any/attribute.rb', line 66 def has_attribute?(attribute) attribute_names.include?(attribute) end |