Module: PeoplesoftModels::EffectiveScope
- Defined in:
- lib/peoplesoft_models/effective_scope.rb
Constant Summary collapse
- COLUMNS =
["effdt", "effseq"]
Instance Method Summary collapse
- #effdt_values(as_of = Date.today) ⇒ Object
- #effective(as_of = Date.today) ⇒ Object
- #effective_key_values(as_of = Date.today) ⇒ Object
- #effective_keys ⇒ Object
- #effseq_values(as_of = Date.today) ⇒ Object
- #non_effective_keys ⇒ Object
Instance Method Details
#effdt_values(as_of = Date.today) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/peoplesoft_models/effective_scope.rb', line 23 def effdt_values(as_of = Date.today) table = self.arel_table columns = self.non_effective_keys + [table[:effdt].maximum.as("effdt")] self.unscoped .select(columns) .where(table[:effdt].lteq(as_of)) .group(self.non_effective_keys) end |
#effective(as_of = Date.today) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/peoplesoft_models/effective_scope.rb', line 7 def effective(as_of = Date.today) table = self.arel_table eff_keys = self.effective_key_values(as_of).as(eff_keys_relation_alias) join_conditions = self.primary_keys.map { |key| table[key].eq(eff_keys[key]) }.reduce(:and) self.joins("INNER JOIN #{eff_keys.to_sql} ON #{join_conditions.to_sql}") end |
#effective_key_values(as_of = Date.today) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/peoplesoft_models/effective_scope.rb', line 15 def effective_key_values(as_of = Date.today) if self.effective_keys.include?("effseq") self.effseq_values else self.effdt_values end end |
#effective_keys ⇒ Object
45 46 47 |
# File 'lib/peoplesoft_models/effective_scope.rb', line 45 def effective_keys self.primary_keys & COLUMNS end |
#effseq_values(as_of = Date.today) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/peoplesoft_models/effective_scope.rb', line 33 def effseq_values(as_of = Date.today) table = self.arel_table effdt_keys = self.effdt_values(as_of).as(effdt_relation_alias) join_columns = self.primary_keys - ["effseq"] join_conditions = join_columns.map { |key| table[key].eq(effdt_keys[key]) }.reduce(:and) self.unscoped .select(join_columns + [table[:effseq].maximum.as("effseq")]) .joins("INNER JOIN #{effdt_keys.to_sql} ON #{join_conditions.to_sql}") .group(join_columns.map { |key| table[key] }) end |
#non_effective_keys ⇒ Object
49 50 51 |
# File 'lib/peoplesoft_models/effective_scope.rb', line 49 def non_effective_keys self.primary_keys - COLUMNS end |