Module: ByStar::Base

Includes:
Between, Directional
Included in:
ActiveRecord::ClassMethods, Mongoid::ByStar::ClassMethods
Defined in:
lib/by_star/base.rb

Instance Method Summary collapse

Methods included from Directional

#after, #before

Methods included from Between

#between_times, #by_calendar_month, #by_day, #by_fortnight, #by_month, #by_quarter, #by_week, #by_weekend, #by_year, #next_day, #next_fortnight, #next_month, #next_week, #next_year, #past_day, #past_fortnight, #past_month, #past_week, #past_year, #today, #tomorrow, #yesterday

Instance Method Details

#by_star_end_field(options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/by_star/base.rb', line 28

def by_star_end_field(options={})
  field = options[:field] ||
      options[:end_field] ||
      @by_star_end_field ||
      by_star_start_field
  field.to_s
end

#by_star_field(*args) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/by_star/base.rb', line 8

def by_star_field(*args)
  options = args.extract_options!
  @by_star_start_field ||= args[0]
  @by_star_end_field   ||= args[1]
  @by_star_offset      ||= options[:offset]
  @by_star_scope       ||= options[:scope]
end

#by_star_offset(options = {}) ⇒ Object



16
17
18
# File 'lib/by_star/base.rb', line 16

def by_star_offset(options = {})
  (options[:offset] || @by_star_offset || 0).seconds
end

#by_star_scope(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/by_star/base.rb', line 36

def by_star_scope(options={})
  scope = options[:scope] || @by_star_scope || self
  if scope.is_a?(Proc)
    if scope.arity == 0
      return instance_exec(&scope)
    else
      return instance_exec(self, &scope)
    end
  else
    return scope
  end
end

#by_star_start_field(options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/by_star/base.rb', line 20

def by_star_start_field(options={})
  field = options[:field] ||
      options[:start_field] ||
      @by_star_start_field ||
      by_star_default_field
  field.to_s
end