Module: DpPublico

Defined in:
lib/dp_publico.rb,
lib/dp_publico/version.rb

Defined Under Namespace

Modules: RakeUtils Classes: DpPublicoEngine

Constant Summary collapse

MIGRATION_PATH =
"#{File.dirname(__FILE__)}/dp_publico/db/migrate"
VERSION =
"0.0.1"
@@added_cucumber_truncation_tables =
[]

Class Method Summary collapse

Class Method Details

.added_cucumber_truncation_tablesObject



13
14
15
# File 'lib/dp_publico.rb', line 13

def self.added_cucumber_truncation_tables
  @@added_cucumber_truncation_tables
end

.application_connect(env) ⇒ Object



41
42
43
# File 'lib/dp_publico.rb', line 41

def self.application_connect(env)
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[env])
end

.inject_table_names!Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/dp_publico.rb', line 66

def self.inject_table_names!

  # TODO: Remover o warning de constantes já carregadas
  Dir[File.join("#{Rails.root}/app/models", '*.rb')].each { |f| require f }
  Dir[File.join("#{Rails.root}/app/models/dp", '*.rb')].each { |f| require f }

  database_name = ActiveRecord::Base.configurations[Rails.env]["database"]
  model_names = ActiveRecord::Base.descendants.collect { |klass| klass.name unless klass.abstract_class? }.compact
  model_names.each do |model_name|
    klass = model_name.constantize
    table_name = klass.table_name
    next if table_name.include? '.'

    if klass.respond_to?(:dp_publico?) && klass.dp_publico?
      new_table_name = "#{DpPublico.publico_config(Rails.env)["database"]}.#{table_name}"
      DpPublico.added_cucumber_truncation_tables << new_table_name
      klass.set_table_name new_table_name
    else
      klass.set_table_name "#{database_name}.#{table_name}"
    end
  end
end

.publico_config(env) ⇒ Object



31
32
33
34
35
# File 'lib/dp_publico.rb', line 31

def self.publico_config(env)
  publico_config = ActiveRecord::Base.configurations["publico"]
  return publico_config[env] if publico_config
  nil
end

.publico_connect(env) ⇒ Object



37
38
39
# File 'lib/dp_publico.rb', line 37

def self.publico_connect(env)
  ActiveRecord::Base.establish_connection(publico_config(env))
end

.tasks_allowed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dp_publico.rb', line 19

def self.tasks_allowed?
  @tasks_allowed == 0
end

.tasks_downObject



27
28
29
# File 'lib/dp_publico.rb', line 27

def self.tasks_down
  @tasks_allowed -= 1
end

.tasks_upObject



23
24
25
# File 'lib/dp_publico.rb', line 23

def self.tasks_up
  @tasks_allowed += 1
end