class FirmRepository

Attributes

client[R]
serializer[R]

Public Class Methods

new(client = ElasticSearchClient, serializer = FirmSerializer) click to toggle source
# File lib/mas/firm_repository.rb, line 4
def initialize(client = ElasticSearchClient, serializer = FirmSerializer)
  @client     = client.new
  @serializer = serializer
end

Public Instance Methods

all() click to toggle source
# File lib/mas/firm_repository.rb, line 31
def all
  response = client.search('firms/_search?size=10000')
  JSON.parse(response.body)
end
delete(id) click to toggle source
# File lib/mas/firm_repository.rb, line 21
def delete(id)
  path = "#{Firm.model_name.plural}/#{id}"
  client.delete(path)
end
find(firm) click to toggle source
# File lib/mas/firm_repository.rb, line 16
def find(firm)
  path = "#{firm.model_name.plural}/#{firm.to_param}"
  JSON.parse(client.find(path).body)
end
from_for(page) click to toggle source
# File lib/mas/firm_repository.rb, line 36
def from_for(page)
  return 0 if page == 1

  ((page - 1) * MAS::RadCore::PAGE_SIZE)
end
store(firm) click to toggle source
# File lib/mas/firm_repository.rb, line 9
def store(firm)
  json = serializer.new(firm).as_json
  path = "#{firm.model_name.plural}/#{firm.to_param}"

  client.store(path, json)
end