Module: Sumac::ExposedObject::IncludedClassMethods
- Defined in:
- lib/sumac/exposed_object.rb
Instance Attribute Summary collapse
-
#__child_accessor__ ⇒ Object
readonly
Returns the value of attribute child_accessor.
Instance Method Summary collapse
- #__exposed_methods__ ⇒ Object
- #child_accessor(method_name = nil) ⇒ Object
- #expose(*method_names) ⇒ Object
- #inherited(base) ⇒ Object
Instance Attribute Details
#__child_accessor__ ⇒ Object (readonly)
Returns the value of attribute child_accessor.
21 22 23 |
# File 'lib/sumac/exposed_object.rb', line 21 def __child_accessor__ @__child_accessor__ end |
Instance Method Details
#__exposed_methods__ ⇒ Object
23 24 25 |
# File 'lib/sumac/exposed_object.rb', line 23 def __exposed_methods__ @__exposed_methods__ ||= [] end |
#child_accessor(method_name = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/sumac/exposed_object.rb', line 27 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
34 35 36 37 38 39 40 41 |
# File 'lib/sumac/exposed_object.rb', line 34 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
16 17 18 19 |
# File 'lib/sumac/exposed_object.rb', line 16 def inherited(base) base.instance_variable_set(:@__exposed_methods__, @__exposed_methods__.dup) base.instance_variable_set(:@__child_accessor__, @__child_accessor__) end |