Class: Marty::Base

Inherits:
ActiveRecord::Base show all
Defined in:
app/models/marty/base.rb

Constant Summary

Constants inherited from ActiveRecord::Base

ActiveRecord::Base::COUNT_SIG, ActiveRecord::Base::DISTINCT_SIG, ActiveRecord::Base::FIND_BY_SIG, ActiveRecord::Base::FIRST_SIG, ActiveRecord::Base::GROUP_SIG, ActiveRecord::Base::JOINS_SIG, ActiveRecord::Base::LAST_SIG, ActiveRecord::Base::LIMIT_SIG, ActiveRecord::Base::MCFLY_PT_SIG, ActiveRecord::Base::NOT_SIG, ActiveRecord::Base::ORDER_SIG, ActiveRecord::Base::PLUCK_SIG, ActiveRecord::Base::SELECT_SIG, ActiveRecord::Base::WHERE_SIG

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from ActiveRecord::Base

joins, old_joins

Class Attribute Details

.struct_attrsObject

Returns the value of attribute struct_attrs.



11
12
13
# File 'app/models/marty/base.rb', line 11

def struct_attrs
  @struct_attrs
end

Class Method Details

.get_final_attrsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/marty/base.rb', line 21

def self.get_final_attrs
  final_attrs = get_struct_attrs
  return final_attrs if final_attrs.present?

  # otherwise raise with error line
  raise "Marty::Base: no attributes for #{self}"

  # for more detailed debugging use this code instead
  # st = caller.detect{|s|s.starts_with?('DELOREAN__')}
  # re = /DELOREAN__([A-Z][a-zA-Z0-9]*)[:]([0-9]+)[:]in `([a-z_0-9]+)__D'/
  # m = re.match(st)
  # if !m
  #   st = "No attributes #{st} #{self}"
  #   puts st unless File.readlines(Rails.root.join('tmp','dlchk')).
  #                   map(&:chop).detect{|l|l==st}
  # else
  #   loc = "#{m[1]}::#{self}::#{m[2]}"
  #   str = "*** No attributes %-40s %-20s   %s" % [loc, m[3], attr]
  #   puts str unless File.readlines(Rails.root.join('tmp','dlchk')).
  #                    map(&:chop).detect{|l|l==str}
  # end
end

.get_struct_attrsObject



14
15
16
17
18
19
# File 'app/models/marty/base.rb', line 14

def self.get_struct_attrs
  self.struct_attrs ||=
    self.attribute_names - Mcfly::COLUMNS.to_a -
    (self.const_defined?('MCFLY_UNIQUENESS') &&
     self.const_get('MCFLY_UNIQUENESS') || []).map(&:to_s)
end

.make_hash(inst) ⇒ Object



44
45
46
47
# File 'app/models/marty/base.rb', line 44

def self.make_hash(inst)
  fa = get_final_attrs
  inst.attributes.slice(*fa)
end

.make_openstruct(inst) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/marty/base.rb', line 49

def self.make_openstruct(inst)
  return nil unless inst
  fa = get_final_attrs
  os = OpenStruct.new(inst.attributes.slice(*fa))
  if self == Marty::DataGrid
    def os.lookup_grid_distinct_entry(pt, params)
      dgh = self.to_h.stringify_keys.slice(
        "id", "group_id", "created_dt", "metadata", "data_type")
      Marty::DataGrid.lookup_grid_distinct_entry_h(pt, params, dgh)
    end
  end
  os
end

.mcfly_pt(pt) ⇒ Object



5
6
7
8
# File 'app/models/marty/base.rb', line 5

def self.mcfly_pt(pt)
  tb = self.table_name
  self.where("#{tb}.obsoleted_dt >= ? AND #{tb}.created_dt < ?", pt, pt)
end