module PeoplesoftModels::EffectiveScope
Constants
- COLUMNS
Public Instance Methods
effdt_values(as_of = Date.today)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/peoplesoft_models/effective_scope.rb, line 45 def effective_keys self.primary_keys & COLUMNS end
effseq_values(as_of = Date.today)
click to toggle source
# 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()
click to toggle source
# File lib/peoplesoft_models/effective_scope.rb, line 49 def non_effective_keys self.primary_keys - COLUMNS end
Private Instance Methods
alias_friendly_tablename()
click to toggle source
# File lib/peoplesoft_models/effective_scope.rb, line 63 def alias_friendly_tablename self.table_name.gsub(/^.*\./, "") end
eff_keys_relation_alias()
click to toggle source
# File lib/peoplesoft_models/effective_scope.rb, line 55 def eff_keys_relation_alias "EFF_KEYS_#{alias_friendly_tablename}" end
effdt_relation_alias()
click to toggle source
# File lib/peoplesoft_models/effective_scope.rb, line 59 def effdt_relation_alias "EFFDT_#{alias_friendly_tablename}" end