Class: Dooly::IdProxy::Base
- Inherits:
-
Object
- Object
- Dooly::IdProxy::Base
- Defined in:
- lib/dooly/id_proxy/base.rb
Class Attribute Summary collapse
-
.finders ⇒ Object
(also: finder)
Returns the value of attribute finders.
-
.model ⇒ Object
Returns the value of attribute model.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(id) ⇒ Base
constructor
A new instance of Base.
- #method_missing(name, *args, &block) ⇒ Object
- #record ⇒ Object
- #respond_to?(name) ⇒ Boolean
Constructor Details
#initialize(id) ⇒ Base
Returns a new instance of Base.
21 22 23 24 |
# File 'lib/dooly/id_proxy/base.rb', line 21 def initialize(id) raise 'idea must have id' if id.blank? @id = id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
47 48 49 |
# File 'lib/dooly/id_proxy/base.rb', line 47 def method_missing(name, *args, &block) self.record.send(name, *args, &block) end |
Class Attribute Details
.finders ⇒ Object Also known as: finder
Returns the value of attribute finders.
6 7 8 |
# File 'lib/dooly/id_proxy/base.rb', line 6 def finders @finders end |
.model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/dooly/id_proxy/base.rb', line 5 def model @model end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
19 20 21 |
# File 'lib/dooly/id_proxy/base.rb', line 19 def id @id end |
Instance Method Details
#record ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dooly/id_proxy/base.rb', line 26 def record return @record if @record self.class.finders.each do |finder| f = finder.to_sym if self.class.model.respond_to?(f) @record = self.class.model.send(f, self.id) end end unless @record @record = self.class.model.find(self.id) end @record end |
#respond_to?(name) ⇒ Boolean
43 44 45 |
# File 'lib/dooly/id_proxy/base.rb', line 43 def respond_to?(name) self.record.respond_to?(name) || super end |