Class: FmStore::Criteria

Inherits:
Object
  • Object
show all
Includes:
Enumerable, FmStore::Criterion::Exclusion, FmStore::Criterion::Inclusion, FmStore::Criterion::Optional
Defined in:
lib/fm_store/criteria.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FmStore::Criterion::Optional

#limit, #order, #skip

Methods included from FmStore::Criterion::Exclusion

#exclude

Methods included from FmStore::Criterion::Inclusion

#custom_query, #fm_id, #id, #in, #search, #where

Constructor Details

#initialize(klass, find_query = false) ⇒ Criteria

Returns a new instance of Criteria.



54
55
56
57
58
59
60
61
62
# File 'lib/fm_store/criteria.rb', line 54

def initialize(klass, find_query = false)
  @params, @options, @klass, @find_query = {}, {}, klass, find_query

  if find_query
    @key_values = {}
    @query_map = []
    @counter = 0
  end
end

Instance Attribute Details

#find_queryObject

Returns the value of attribute find_query.



50
51
52
# File 'lib/fm_store/criteria.rb', line 50

def find_query
  @find_query
end

#klassObject (readonly)

Returns the value of attribute klass.



49
50
51
# File 'lib/fm_store/criteria.rb', line 49

def klass
  @klass
end

#optionsObject (readonly)

Returns the value of attribute options.



49
50
51
# File 'lib/fm_store/criteria.rb', line 49

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



49
50
51
# File 'lib/fm_store/criteria.rb', line 49

def params
  @params
end

#raw_paramsObject (readonly)

Returns the value of attribute raw_params.



49
50
51
# File 'lib/fm_store/criteria.rb', line 49

def raw_params
  @raw_params
end

Instance Method Details

#allObject



84
85
86
# File 'lib/fm_store/criteria.rb', line 84

def all
  reader.execute
end

#each(&block) ⇒ Object



68
69
70
# File 'lib/fm_store/criteria.rb', line 68

def each(&block)
  reader.execute.each { |record| yield record } if block_given?
end

#readerObject



64
65
66
# File 'lib/fm_store/criteria.rb', line 64

def reader
  @reader ||= FmReader.new(self)
end

#to_sObject



72
73
74
# File 'lib/fm_store/criteria.rb', line 72

def to_s
  "#{params.inspect}, #{options.inspect}"
end

#totalObject



76
77
78
79
80
81
82
# File 'lib/fm_store/criteria.rb', line 76

def total
  original_max_record = options[:max_records]
  count = paginate(:per_page => 1).total_entries
  limit(original_max_record)

  return count
end