Class: Marbu::Models::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/marbu/models/mrf/query.rb

Constant Summary collapse

DEFAULT_DATE_FIELDS =
[:created_at]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ext_params = {}) ⇒ Query

Returns a new instance of Query.



10
11
12
13
14
15
# File 'lib/marbu/models/mrf/query.rb', line 10

def initialize( ext_params = {} )
  params                  = default_params.merge( ext_params.keep_if{|k,v|v} )
  @condition              = params[:condition]
  @datetime_fields        = params[:datetime_fields]
  @static                 = params[:static]
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



8
9
10
# File 'lib/marbu/models/mrf/query.rb', line 8

def condition
  @condition
end

#datetime_fieldsObject

Returns the value of attribute datetime_fields.



8
9
10
# File 'lib/marbu/models/mrf/query.rb', line 8

def datetime_fields
  @datetime_fields
end

#staticObject

Returns the value of attribute static.



8
9
10
# File 'lib/marbu/models/mrf/query.rb', line 8

def static
  @static
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/marbu/models/mrf/query.rb', line 27

def blank?
  !present?
end

#default_paramsObject



17
18
19
20
21
# File 'lib/marbu/models/mrf/query.rb', line 17

def default_params
  {
    datetime_fields:      DEFAULT_DATE_FIELDS
  }
end

#present?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/marbu/models/mrf/query.rb', line 23

def present?
  condition.present? || !datetime_fields.eql?(DEFAULT_DATE_FIELDS) || static.present?
end

#serializable_hashObject



31
32
33
34
35
36
37
# File 'lib/marbu/models/mrf/query.rb', line 31

def serializable_hash
  {
    condition:            condition,
    datetime_fields:      datetime_fields,
    static:               static
  }.delete_if{|k,v|v.blank?}
end