Class: Intercom::Lib::DynamicAccessorsOnMethodMissing

Inherits:
Object
  • Object
show all
Defined in:
lib/intercom/lib/dynamic_accessors_on_method_missing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_sym, *arguments, object) ⇒ DynamicAccessorsOnMethodMissing

Returns a new instance of DynamicAccessorsOnMethodMissing.



7
8
9
10
11
12
13
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 7

def initialize(method_sym, *arguments, object)
  @method_sym = method_sym
  @method_string = method_sym.to_s
  @arguments = arguments
  @klass = object.class
  @object = object
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 5

def arguments
  @arguments
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 5

def klass
  @klass
end

#method_stringObject (readonly)

Returns the value of attribute method_string.



5
6
7
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 5

def method_string
  @method_string
end

#method_symObject (readonly)

Returns the value of attribute method_sym.



5
6
7
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 5

def method_sym
  @method_sym
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 5

def object
  @object
end

Instance Method Details

#define_accessors_or_call(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/intercom/lib/dynamic_accessors_on_method_missing.rb', line 15

def define_accessors_or_call(&block)
  return yield if not_an_accessor?
  if setter?
    Lib::DynamicAccessors.define_accessors(attribute_name, *arguments, object)
    object.send(method_sym, *arguments)
  else # getter
    if trying_to_access_private_variable?
      yield
    else
      raise Intercom::AttributeNotSetError, attribute_not_set_error_message
    end
  end
end