module Tradesman::ClassMethods

Attributes

store[R]

Public Instance Methods

adapter() click to toggle source
# File lib/tradesman/class_methods.rb, line 5
def adapter
  Tradesman.adapter.new(store)
end
go(obj, params, *context, &block) click to toggle source
# File lib/tradesman/class_methods.rb, line 9
def go(obj, params, *context, &block)
  run_and_convert_exceptions { run(tzu_params(obj, params), *context, &block) }
end
go!(obj, params, *context) click to toggle source
# File lib/tradesman/class_methods.rb, line 13
def go!(obj, params, *context)
  run_and_convert_exceptions { run!(tzu_params(obj, params), *context) }
end
id_from_obj(obj) click to toggle source
# File lib/tradesman/class_methods.rb, line 27
def id_from_obj(obj)
  id = obj.respond_to?(:id) ? obj.id : obj
  Integer(id)
rescue ArgumentError
  raise Tradesman::InvalidId.new('You must pass an object that responds to id or an integer')
end
prepare_ids(obj) click to toggle source
# File lib/tradesman/class_methods.rb, line 21
def prepare_ids(obj)
  return obj if (obj.is_a?(Hash) && !obj.respond_to?(:id))
  return id_from_obj(obj) unless (obj.is_a?(Array) || obj.respond_to?(:push))
  obj.map { |object| id_from_obj(object) }
end
prepare_params(params) click to toggle source
# File lib/tradesman/class_methods.rb, line 34
def prepare_params(params)
  return params unless params.is_a? Array
  { params: params }
end
tzu_params(obj, params) click to toggle source
# File lib/tradesman/class_methods.rb, line 17
def tzu_params(obj, params)
  { id: prepare_ids(obj) }.merge(prepare_params(params))
end