Class: CohortAnalysis::Strategy
- Inherits:
-
Arel::Nodes::Node
- Object
- Arel::Nodes::Node
- CohortAnalysis::Strategy
- Defined in:
- lib/cohort_analysis/strategy.rb,
lib/cohort_analysis/strategy/big.rb,
lib/cohort_analysis/strategy/strict.rb
Defined Under Namespace
Modules: AlwaysTrue, Impossible Classes: Big, Strict
Constant Summary collapse
- DEFAULT_STRATEGY =
:big
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#minimum_size ⇒ Object
readonly
Returns the value of attribute minimum_size.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#select_manager ⇒ Object
readonly
Returns the value of attribute select_manager.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #expr ⇒ Object
- #final ⇒ Object
-
#initialize(select_manager, characteristics, options = {}) ⇒ Strategy
constructor
A new instance of Strategy.
Constructor Details
#initialize(select_manager, characteristics, options = {}) ⇒ Strategy
Returns a new instance of Strategy.
33 34 35 36 37 38 39 40 41 |
# File 'lib/cohort_analysis/strategy.rb', line 33 def initialize(select_manager, characteristics, = {}) @select_manager = select_manager @table_name = select_manager.source.left.name @table = Arel::Table.new table_name @original = characteristics.dup @current = characteristics.dup @minimum_size = .fetch(:minimum_size, 1) @final_mutex = Mutex.new end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
28 29 30 |
# File 'lib/cohort_analysis/strategy.rb', line 28 def current @current end |
#minimum_size ⇒ Object (readonly)
Returns the value of attribute minimum_size.
29 30 31 |
# File 'lib/cohort_analysis/strategy.rb', line 29 def minimum_size @minimum_size end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
27 28 29 |
# File 'lib/cohort_analysis/strategy.rb', line 27 def original @original end |
#select_manager ⇒ Object (readonly)
Returns the value of attribute select_manager.
26 27 28 |
# File 'lib/cohort_analysis/strategy.rb', line 26 def select_manager @select_manager end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
31 32 33 |
# File 'lib/cohort_analysis/strategy.rb', line 31 def table @table end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
30 31 32 |
# File 'lib/cohort_analysis/strategy.rb', line 30 def table_name @table_name end |
Class Method Details
.create(select_manager, characteristics, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cohort_analysis/strategy.rb', line 4 def create(select_manager, characteristics, = {}) = .symbolize_keys strategy = if .has_key? :strategy [:strategy] elsif .has_key? :priority :strict else DEFAULT_STRATEGY end const_get(strategy.to_s.camelcase).new(select_manager, characteristics, ) end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/cohort_analysis/strategy.rb', line 59 def ==(other) other.is_a?(Strategy) and table_name == other.table_name and minimum_size = other.minimum_size and original == other.original end |
#expr ⇒ Object
55 56 57 |
# File 'lib/cohort_analysis/strategy.rb', line 55 def expr final.to_sql end |
#final ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cohort_analysis/strategy.rb', line 43 def final @final || if @final_mutex.try_lock begin @final ||= resolve! ensure @final_mutex.unlock end else Impossible end end |