Class: ActiveFacts::API::RoleProxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveFacts::API::RoleProxy
- Defined in:
- lib/activefacts/api/role_proxy.rb
Overview
When you use the accessor method created by has_one, one_to_one, or maybe, you get a RoleProxy for the actual value. This behaves almost exactly as the value, but it knows through which role you fetched it. That will allow it to verbalise itself using the correct reading for that role.
Don’t use “SomeClass === role_value” to test the type, use “role_value.is_a?(SomeClass)” instead.
In future, retrieving a value by indexing into a RoleValues array will do the same thing.
Instance Method Summary collapse
-
#==(o) ⇒ Object
:nodoc:.
-
#class ⇒ Object
:nodoc:.
-
#eql?(o) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
REVISIT: Should Proxies hash and eql? the same as their wards?.
-
#initialize(role, o = nil) ⇒ RoleProxy
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#is_a?(klass) ⇒ Boolean
:nodoc:.
-
#method_missing(m, *a, &b) ⇒ Object
:nodoc:.
-
#object_id ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(role, o = nil) ⇒ RoleProxy
:nodoc:
21 22 23 24 |
# File 'lib/activefacts/api/role_proxy.rb', line 21 def initialize(role, o = nil) #:nodoc: @role = role # REVISIT: Use this to implement verbalise() __setobj__(o) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 34 |
# File 'lib/activefacts/api/role_proxy.rb', line 26 def method_missing(m, *a, &b) #:nodoc: begin super # Delegate first rescue NoMethodError => e __getobj__.method_missing(m, *a, &b) rescue => e raise end end |
Instance Method Details
#==(o) ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/activefacts/api/role_proxy.rb', line 61 def ==(o) #:nodoc: __getobj__.==(o) end |
#class ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/activefacts/api/role_proxy.rb', line 36 def class #:nodoc: __getobj__.class end |
#eql?(o) ⇒ Boolean
:nodoc:
57 58 59 |
# File 'lib/activefacts/api/role_proxy.rb', line 57 def eql?(o) #:nodoc: self.class == o.class and __getobj__.eql?(o) end |
#hash ⇒ Object
REVISIT: Should Proxies hash and eql? the same as their wards?
53 54 55 |
# File 'lib/activefacts/api/role_proxy.rb', line 53 def hash #:nodoc: __getobj__.hash ^ self.class.hash end |
#inspect ⇒ Object
:nodoc:
65 66 67 |
# File 'lib/activefacts/api/role_proxy.rb', line 65 def inspect #:nodoc: "Proxy:#{__getobj__.inspect}" end |
#is_a?(klass) ⇒ Boolean
:nodoc:
40 41 42 |
# File 'lib/activefacts/api/role_proxy.rb', line 40 def is_a? klass #:nodoc: __getobj__.is_a? klass end |
#object_id ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/activefacts/api/role_proxy.rb', line 48 def object_id #:nodoc: __getobj__.object_id end |
#to_s ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/activefacts/api/role_proxy.rb', line 44 def to_s #:nodoc: __getobj__.to_s end |