Class: FirmRepository
- Inherits:
-
Object
- Object
- FirmRepository
- Defined in:
- lib/mas/firm_repository.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
- #from_for(page) ⇒ Object
-
#initialize(client = ElasticSearchClient, serializer = FirmSerializer) ⇒ FirmRepository
constructor
A new instance of FirmRepository.
- #search(query, page: 1) ⇒ Object
- #store(firm) ⇒ Object
Constructor Details
#initialize(client = ElasticSearchClient, serializer = FirmSerializer) ⇒ FirmRepository
Returns a new instance of FirmRepository.
4 5 6 7 |
# File 'lib/mas/firm_repository.rb', line 4 def initialize(client = ElasticSearchClient, serializer = FirmSerializer) @client = client.new @serializer = serializer end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
2 3 4 |
# File 'lib/mas/firm_repository.rb', line 2 def client @client end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
2 3 4 |
# File 'lib/mas/firm_repository.rb', line 2 def serializer @serializer end |
Instance Method Details
#from_for(page) ⇒ Object
21 22 23 24 25 |
# File 'lib/mas/firm_repository.rb', line 21 def from_for(page) return 0 if page == 1 ((page - 1) * MAS::RadCore::PAGE_SIZE) end |
#search(query, page: 1) ⇒ Object
16 17 18 19 |
# File 'lib/mas/firm_repository.rb', line 16 def search(query, page: 1) response = client.search("firms/_search?from=#{from_for(page)}", query) SearchResult.new(response, page: page) end |
#store(firm) ⇒ Object
9 10 11 12 13 14 |
# 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 |