Module: CalendarSniper::ClassMethods
- Defined in:
- lib/calendar_sniper.rb
Instance Attribute Summary collapse
-
#_filterable_by_date_range_field ⇒ Object
readonly
Returns the value of attribute _filterable_by_date_range_field.
Instance Method Summary collapse
-
#filterable_by_date_range(with_name = :created_at) ⇒ Object
Set the field to search date range on in your model.
-
#search_in_date_range(by_direction, with_date) ⇒ Object
Search through the date range in a given direction.
Instance Attribute Details
#_filterable_by_date_range_field ⇒ Object (readonly)
Returns the value of attribute _filterable_by_date_range_field.
31 32 33 |
# File 'lib/calendar_sniper.rb', line 31 def _filterable_by_date_range_field @_filterable_by_date_range_field end |
Instance Method Details
#filterable_by_date_range(with_name = :created_at) ⇒ Object
Set the field to search date range on in your model.
Example:
filterable_by_date_range :internal_lead_received_at
39 40 41 |
# File 'lib/calendar_sniper.rb', line 39 def filterable_by_date_range(with_name = :created_at) @_filterable_by_date_range_field = with_name.to_s end |
#search_in_date_range(by_direction, with_date) ⇒ Object
Search through the date range in a given direction. Uses the field given in the filterable_by_date_range
macro that you can add to ActiveRecord, otherwise it defaults to ‘created_at’.
46 47 48 49 |
# File 'lib/calendar_sniper.rb', line 46 def search_in_date_range(by_direction, with_date) logger.debug "Searched #{date_field} on #{self.class.name} with a scope" where("#{table_name}.#{date_field} #{by_direction}= ?", coalesce_date(with_date, by_direction)) end |