Module: SmoothOperator::Operator

Included in:
Base
Defined in:
lib/smooth_operator/operator.rb

Defined Under Namespace

Modules: ClassMethods, HelperMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



42
43
44
# File 'lib/smooth_operator/operator.rb', line 42

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#headersObject



11
12
13
# File 'lib/smooth_operator/operator.rb', line 11

def headers
  {}
end

#make_the_call(http_verb, relative_path = '', data = {}, options = {}) ⇒ Object



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

def make_the_call(http_verb, relative_path = '', data = {}, options = {})
  options ||= {}

  relative_path = resource_path(relative_path)

  options[:headers]         = headers.merge(options[:headers] || {})
  options[:parent_object] ||= _options[:parent_object]

  call_args = before_request(http_verb, relative_path, data, options)

  self.class.make_the_call(*call_args) do |remote_call|
    yield(remote_call)
  end
end

#resource_path(relative_path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/smooth_operator/operator.rb', line 30

def resource_path(relative_path)
  if Helpers.absolute_path?(relative_path)
    Helpers.remove_initial_slash(relative_path)
  elsif persisted?
    id = Helpers.primary_key(self)

    Helpers.present?(relative_path) ? "#{id}/#{relative_path}" : id.to_s
  else
    relative_path
  end
end