Class: Dayman::Resource
- Inherits:
-
Object
- Object
- Dayman::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/dayman/resource.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#id ⇒ Object
Returns the value of attribute id.
-
#relationships ⇒ Object
Returns the value of attribute relationships.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id: nil, attributes: {}) ⇒ Resource
constructor
A new instance of Resource.
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(id: nil, attributes: {}) ⇒ Resource
Returns a new instance of Resource.
46 47 48 49 |
# File 'lib/dayman/resource.rb', line 46 def initialize(id: nil, attributes: {}) @id = id @attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
51 52 53 |
# File 'lib/dayman/resource.rb', line 51 def method_missing(name, *args, &block) attributes.key?(name) ? attributes[name] : super end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/dayman/resource.rb', line 4 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/dayman/resource.rb', line 4 def id @id end |
#relationships ⇒ Object
Returns the value of attribute relationships.
4 5 6 |
# File 'lib/dayman/resource.rb', line 4 def relationships @relationships end |
Class Method Details
.has_many(relationship_name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dayman/resource.rb', line 27 def has_many(relationship_name) instance_variable_name = "@#{relationship_name}".to_sym define_method(relationship_name) do if instance_variable_defined?(instance_variable_name) instance_variable_get(instance_variable_name) else instance_variable_set(instance_variable_name, []) end end end |
.has_one(relationship_name) ⇒ Object
23 24 25 |
# File 'lib/dayman/resource.rb', line 23 def has_one(relationship_name) attr_accessor relationship_name end |
.path ⇒ Object
19 20 21 |
# File 'lib/dayman/resource.rb', line 19 def path name.demodulize.underscore.pluralize end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
55 56 57 |
# File 'lib/dayman/resource.rb', line 55 def respond_to_missing?(name, include_private = false) attributes.key?(name) || super end |