Class: Integrative::Integration

Inherits:
Object
  • Object
show all
Defined in:
lib/integrative/integration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, integrator_class, options) ⇒ Integration

Returns a new instance of Integration.



9
10
11
12
13
14
# File 'lib/integrative/integration.rb', line 9

def initialize(name, integrator_class, options)
  @name = name
  @integrator_class = integrator_class
  @integrated_class = name.to_s.camelize.singularize.constantize
  @init_options = options
end

Instance Attribute Details

#call_optionsObject

Returns the value of attribute call_options.



7
8
9
# File 'lib/integrative/integration.rb', line 7

def call_options
  @call_options
end

#init_optionsObject

Returns the value of attribute init_options.



6
7
8
# File 'lib/integrative/integration.rb', line 6

def init_options
  @init_options
end

#integrated_classObject

Returns the value of attribute integrated_class.



5
6
7
# File 'lib/integrative/integration.rb', line 5

def integrated_class
  @integrated_class
end

#integrator_classObject

Returns the value of attribute integrator_class.



4
5
6
# File 'lib/integrative/integration.rb', line 4

def integrator_class
  @integrator_class
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/integrative/integration.rb', line 3

def name
  @name
end

Instance Method Details

#integrated_keyObject



47
48
49
50
# File 'lib/integrative/integration.rb', line 47

def integrated_key
  default_integrated_key = "#{integrator_class.name.underscore}_id"
  init_options[:integrated_key] || default_integrated_key
end

#integrator_keyObject



43
44
45
# File 'lib/integrative/integration.rb', line 43

def integrator_key
  init_options[:integrator_key] || :id
end

#invalidateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/integrative/integration.rb', line 16

def invalidate
  if call_options.blank? && init_options[:requires].present?
    raise Errors::RuntimeOptionMissingError.new(self)
  end

  if call_options.present? && init_options[:requires].blank?
    raise Errors::UnexpectedRuntimeOptionError.new(self)
  end

  if call_options.present? && init_options[:requires].present?
    unexpected_options = call_options.keys - init_options[:requires]
    missing_options = init_options[:requires] - call_options.keys

    if unexpected_options.present?
      raise Errors::TooManyRuntimeOptionsError.new(self, unexpected_options)
    end

    if missing_options.present?
      raise Errors::TooLittleRuntimeOptionsError.new(self, missing_options)
    end
  end
end

#setterObject



39
40
41
# File 'lib/integrative/integration.rb', line 39

def setter
  "#{name}="
end