Class: ActiveRecord::LiteView

Inherits:
Base
  • Object
show all
Defined in:
lib/vex/active_record/lite_view.rb

Overview

TODO: LiteViews do not or not always support type information. Therefore values might be returned as strings, when in fact they are numbers. This behaviour is heavily database dependant.

It would be great to fix it.

Class Method Summary collapse

Class Method Details

.drop_view(klass, view) ⇒ Object


45
46
47
# File 'lib/vex/active_record/lite_view.rb', line 45

def self.drop_view(klass, view)
  destroy_all :name => view_name(:klass => klass, :view => view)
end

.make(klass, view, sql) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vex/active_record/lite_view.rb', line 49

def self.make(klass, view, sql)
  name = view_name(:klass => klass, :view => view)
  
  view = find_first(:name => name, :sql => sql)
  view ||= locked(name) do
    find_first(:name => name, :sql => sql) || create!(:name => name, :sql => sql)
  end

  # create a view class and return its name
  view_klass = Class.new(ActiveRecord::Base)
  view_klass.set_table_name name

  klass_name = "LV_#{name.camelize}"
  klass.send(:remove_const, klass_name) if klass.const_defined?(klass_name)
  klass.const_set(klass_name, view_klass)

  klass_name
end