Module: Sumac::ExposedObject::ExtendedClassMethods
- Defined in:
- lib/sumac/exposed_object.rb
Instance Method Summary collapse
- #__child__(key) ⇒ Object
- #__exposed_methods__ ⇒ Object
- #__native_id__ ⇒ Object
- #__sumac_exposed_object__ ⇒ Object
- #child_accessor(method_name = nil) ⇒ Object
- #expose(*method_names) ⇒ Object
- #inherited(base) ⇒ Object
Instance Method Details
#__child__(key) ⇒ Object
95 96 97 98 |
# File 'lib/sumac/exposed_object.rb', line 95 def __child__(key) raise 'child_accessor not defined' unless @__child_accessor__ __send__(@__child_accessor__, key) end |
#__exposed_methods__ ⇒ Object
100 101 102 |
# File 'lib/sumac/exposed_object.rb', line 100 def __exposed_methods__ @__exposed_methods__ ||= [] end |
#__native_id__ ⇒ Object
104 105 106 |
# File 'lib/sumac/exposed_object.rb', line 104 def __native_id__ __id__ end |
#__sumac_exposed_object__ ⇒ Object
108 109 |
# File 'lib/sumac/exposed_object.rb', line 108 def __sumac_exposed_object__ end |
#child_accessor(method_name = nil) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/sumac/exposed_object.rb', line 111 def child_accessor(method_name = nil) unless method_name.is_a?(Symbol) || method_name.is_a?(String) raise ArgumentError, "'child_accessor' expects a method name as a string for symbol" end @__child_accessor__ = method_name.to_s end |
#expose(*method_names) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/sumac/exposed_object.rb', line 118 def expose(*method_names) raise ArgumentError, 'at least one argument expected' if method_names.empty? unless method_names.each { |method_name| method_name.is_a?(Symbol) || method_name.is_a?(String) } raise 'only symbols or strings expected' end @__exposed_methods__ ||= [] @__exposed_methods__.concat(method_names.map(&:to_s)) end |
#inherited(base) ⇒ Object
90 91 92 93 |
# File 'lib/sumac/exposed_object.rb', line 90 def inherited(base) base.instance_variable_set(:@__exposed_methods__, @__exposed_methods__.dup) base.instance_variable_set(:@__child_accessor__, @__child_accessor__) end |