Module: Driftrock::Service::DriftrockModel::ActiveRecordSimulator

Defined in:
lib/driftrock-service/driftrock_model.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/driftrock-service/driftrock_model.rb', line 38

def method_missing(method_sym, *args, &block)
  if method_sym =~ /^find_by_.+$/
    type = method_sym.to_s.gsub(/^find_by_/, '')
    object_hash = get_from_api_method.call("/#{type}/#{args.first}")
    new(object_hash)
  else
    super(method_sym, *args)
  end
end

Instance Method Details

#allObject



48
49
50
51
52
53
# File 'lib/driftrock-service/driftrock_model.rb', line 48

def all
  object_arr = get_from_api_method.call("/")
  object_arr.map do |object_hash|
    new(object_hash)
  end
end

#create(data) ⇒ Object



55
56
57
# File 'lib/driftrock-service/driftrock_model.rb', line 55

def create(data)
  post_to_api_method.call("/new", data)
end

#find(id) ⇒ Object



33
34
35
36
# File 'lib/driftrock-service/driftrock_model.rb', line 33

def find(id)
  object_hash = get_from_api_method.call("/#{id}")
  new(object_hash)
end