Class: FmStore::FmReader

Inherits:
Object
  • Object
show all
Includes:
Paging
Defined in:
lib/fm_store/criteria.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Paging

#page, #paginate, #per_page

Constructor Details

#initialize(criteria) ⇒ FmReader

Returns a new instance of FmReader.



15
16
17
# File 'lib/fm_store/criteria.rb', line 15

def initialize(criteria)
  @criteria = criteria
end

Instance Attribute Details

#criteriaObject (readonly)

Returns the value of attribute criteria.



11
12
13
# File 'lib/fm_store/criteria.rb', line 11

def criteria
  @criteria
end

Instance Method Details

#countObject



19
20
21
# File 'lib/fm_store/criteria.rb', line 19

def count
  @count ||= 0
end

#execute(paginating = false) ⇒ Object

This is the method to really get down and grab the records The criteria find_query flag will be set to true if it is a -findquery



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fm_store/criteria.rb', line 25

def execute(paginating = false)
  ActiveSupport::Notifications.instrument(:fm_store_execute, :model_name => klass.to_s, :params => params, :options => options) do
    conn = Connection.establish_connection(klass)

    if find_query
      # We will be using the -findquery command
      rs = conn.send(:get_records, "-findquery", params, options)
    else
      rs = conn.find(params, options)
    end

    @count = rs.foundset_count if paginating

    FmStore::Builders::Collection.build(rs, klass)
  end
end