Module: Waves::Layers::ORM::ActiveRecord

Defined in:
lib/waves/layers/orm/providers/active_record.rb

Overview

Sets up the ActiveRecord connection and configures AutoCode on Models, so that constants in that namespace get loaded from file or created as subclasses of Models::Default

Defined Under Namespace

Modules: ControllerMethods

Class Method Summary collapse

Class Method Details

.included(app) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/waves/layers/orm/providers/active_record.rb', line 22

def self.included(app)

  require 'active_record'
  require "#{File.dirname(__FILE__)}/active_record/tasks/schema"    if defined?(Rake)
  require "#{File.dirname(__FILE__)}/active_record/tasks/generate"  if defined?(Rake)
  
  def app.database
    unless @database
      ::ActiveRecord::Base.establish_connection(config.database)
      @database = ::ActiveRecord::Base.connection
    end
    @database
  end
              
  app.auto_create_module( :Models ) do
    auto_create_class :Default, ::ActiveRecord::Base
    auto_load :Default, :directories => [ :models ]
    auto_create_class true, app::Models::Default
    auto_load true, :directories => [ :models ]

    auto_eval true do
      next if self.basename == "Default"
      app.database
      set_table_name self.basename.snake_case.pluralize.intern
    end
  end
  
  Waves::Controllers::Base.instance_eval do
    include Waves::Layers::ORM::ActiveRecord::ControllerMethods
  end
  
end