Module: SmoothOperator::Operator::HelperMethods

Extended by:
HelperMethods
Included in:
HelperMethods
Defined in:
lib/smooth_operator/operator.rb

Instance Method Summary collapse

Instance Method Details

#get_me_an_operator(options) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/smooth_operator/operator.rb', line 111

def get_me_an_operator(options)
  if options[:parallel_connection].nil?
    Operators::Faraday
  else
    options[:connection] = options.delete(:parallel_connection)
    Operators::Typhoeus
  end
end

#populate_options(object, options) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/smooth_operator/operator.rb', line 120

def populate_options(object, options)
  options ||= {}

  ClassMethods::OPTIONS.each do |option, default|
    options[option] ||= object.send(option)
  end

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

  parent_object = options[:parent_object]

  if !parent_object.nil? && options[:ignore_parent] != true
    id = Helpers.primary_key(parent_object)

    id = "#{id}/" if Helpers.present?(id)

    options[:resources_name] ||= "#{parent_object.class.resources_name}/#{id}#{object.resources_name}"
  end

  options
end

#strip_params(object, http_verb, data) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/smooth_operator/operator.rb', line 142

def strip_params(object, http_verb, data)
  data ||= {}

  if [:get, :head, :delete].include?(http_verb)
    [object.query_string(data), nil]
  else
    [object.query_string({}), data]
  end
end