Module: StateOfTheNation::ClassMethods
- Defined in:
- lib/state_of_the_nation.rb
Instance Attribute Summary collapse
-
#finish_key ⇒ Object
Returns the value of attribute finish_key.
-
#parent_association ⇒ Object
Returns the value of attribute parent_association.
-
#prevent_multiple_active ⇒ Object
Returns the value of attribute prevent_multiple_active.
-
#start_key ⇒ Object
Returns the value of attribute start_key.
Instance Method Summary collapse
- #considered_active ⇒ Object
- #from(start_key) ⇒ Object
- #has_active(association_plural) ⇒ Object
- #has_uniquely_active(association_singular) ⇒ Object
- #until(finish_key) ⇒ Object
- #with_identity_cache ⇒ Object
Instance Attribute Details
#finish_key ⇒ Object
Returns the value of attribute finish_key.
15 16 17 |
# File 'lib/state_of_the_nation.rb', line 15 def finish_key @finish_key end |
#parent_association ⇒ Object
Returns the value of attribute parent_association.
15 16 17 |
# File 'lib/state_of_the_nation.rb', line 15 def parent_association @parent_association end |
#prevent_multiple_active ⇒ Object
Returns the value of attribute prevent_multiple_active.
15 16 17 |
# File 'lib/state_of_the_nation.rb', line 15 def prevent_multiple_active @prevent_multiple_active end |
#start_key ⇒ Object
Returns the value of attribute start_key.
15 16 17 |
# File 'lib/state_of_the_nation.rb', line 15 def start_key @start_key end |
Instance Method Details
#considered_active ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/state_of_the_nation.rb', line 17 def considered_active def from(start_key) @start_key = start_key self end def until(finish_key) @finish_key = finish_key define_method "active?" do |time = Time.now.utc| (finish.blank? || round_if_should(finish) > round_if_should(time)) && round_if_should(start) <= round_if_should(time) end scope :active, lambda { |time = Time.now.utc| where(QueryString.query_for(:active_scope, self), round_if_should(time), round_if_should(time)) } end self end |
#from(start_key) ⇒ Object
18 19 20 21 |
# File 'lib/state_of_the_nation.rb', line 18 def from(start_key) @start_key = start_key self end |
#has_active(association_plural) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/state_of_the_nation.rb', line 38 def has_active(association_plural) @association_plural = association_plural add_child_methods(plural: @association_plural, single: false, with_identity_cache: false) def with_identity_cache add_child_methods(plural: @association_plural, single: false, with_identity_cache: true) self end self end |
#has_uniquely_active(association_singular) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/state_of_the_nation.rb', line 50 def has_uniquely_active(association_singular) @association_plural = association_singular.to_s.pluralize add_child_methods(plural: @association_plural, single: true, with_identity_cache: false) def with_identity_cache add_child_methods(plural: @association_plural, single: true, with_identity_cache: true) self end self end |
#until(finish_key) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/state_of_the_nation.rb', line 23 def until(finish_key) @finish_key = finish_key define_method "active?" do |time = Time.now.utc| (finish.blank? || round_if_should(finish) > round_if_should(time)) && round_if_should(start) <= round_if_should(time) end scope :active, lambda { |time = Time.now.utc| where(QueryString.query_for(:active_scope, self), round_if_should(time), round_if_should(time)) } end |
#with_identity_cache ⇒ Object
42 43 44 45 |
# File 'lib/state_of_the_nation.rb', line 42 def with_identity_cache add_child_methods(plural: @association_plural, single: false, with_identity_cache: true) self end |