Module: Idapted::ActsAsReadonly::ClassMethods

Defined in:
lib/eco_apps/acts_as_readonly.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_readonly(name, options = {}) ⇒ Object Also known as: acts_as_remote



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/eco_apps/acts_as_readonly.rb', line 8

def acts_as_readonly(name, options = {})
  cattr_accessor :app_name, :rails_origin_table_name
  self.app_name = name

  unless Rails.env == "test"
    config = YAML.load(options[:database]||CoreService.app(name).database)
    connection = (config[Rails.env] || config["production"] || config)
    establish_connection connection  #activate readonly connection
      
    db_name = self.connection.current_database
    prefix = table_name.include?(db_name) ? "" : db_name + "."
    tbl = (options[:table_name]||table_name).to_s

    self.rails_origin_table_name = tbl
    set_table_name(prefix + tbl)
  else
    generate_table(self.table_name)
  end

  unless options[:readonly] == false or Rails.env == "test"
    include Idapted::ActsAsReadonly::InstanceMethods
    extend Idapted::ActsAsReadonly::SingletonMethods
  end
end