Class: Marbu::Models::Query
- Inherits:
-
Object
- Object
- Marbu::Models::Query
- Defined in:
- lib/marbu/models/mrf/query.rb
Constant Summary collapse
- DEFAULT_DATE_FIELDS =
[:created_at]
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#datetime_fields ⇒ Object
Returns the value of attribute datetime_fields.
-
#static ⇒ Object
Returns the value of attribute static.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #default_params ⇒ Object
-
#initialize(ext_params = {}) ⇒ Query
constructor
A new instance of Query.
- #present? ⇒ Boolean
- #serializable_hash ⇒ Object
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
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/marbu/models/mrf/query.rb', line 8 def condition @condition end |
#datetime_fields ⇒ Object
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 |
#static ⇒ Object
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
27 28 29 |
# File 'lib/marbu/models/mrf/query.rb', line 27 def blank? !present? end |
#default_params ⇒ Object
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
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_hash ⇒ Object
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 |