Class: Arfy::Environment
- Inherits:
-
Object
show all
- Defined in:
- lib/arfy/environment.rb
Defined Under Namespace
Classes: EnvWorkdirConfiguration
Instance Method Summary
collapse
Instance Method Details
#augment(object_or_module_name, module_name = nil) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/arfy/environment.rb', line 66
def augment(object_or_module_name, module_name=nil)
object, module_name = initialize_module_name(object_or_module_name, module_name)
unless object
if block_given?
object = yield
else
object = Object.new
end
end
pimp_object(object, module_name)
end
|
TODO:should be possible change the result of this method to configure the paths
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/arfy/environment.rb', line 44
def configured_paths
workdir = EnvWorkdirConfiguration.new
paths = {}
paths["config/database"] = workdir.database_config_path
paths["db/seeds"] = workdir.seed_rb_path
migrate_path = String.new(workdir.migration_dirpath)
def migrate_path.to_a
[self]
end
paths["db/migrate"] = migrate_path
paths["db/schema"] = workdir.schema_path
ENV["SCHEMA"] = paths["db/schema"]
if paths["db/schema"].index("/") == 0
path = paths["db/schema"]
else
path = File.join(Dir.pwd, paths["db/schema"])
end
FileUtils.mkdir_p(File.dirname(path))
paths
end
|
#create_config(options_param = {}) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/arfy/environment.rb', line 102
def create_config(options_param={})
config = {
"config/database" => "config/database.yml",
"db/seeds" => "db/seeds.rb",
"db/migrate" => "db/migrate"}.merge(options_param)
new_hash = {
"config" => {
"database" => config["config/database"]
},
"db" => {
"seeds" => config["db/seeds"],
"migrate" => config["db/migrate"],
"schema" => config["db/schema"]}
}
File.open(".arfy", "w") do |f|
f << new_hash.to_yaml
end
end
|
#database_connect ⇒ Object
96
97
98
99
100
|
# File 'lib/arfy/environment.rb', line 96
def database_connect
database_configurations = Rails.application.config.database_configuration
env_db_configuration = database_configurations[Rails.env]
ActiveRecord::Base.establish_connection(env_db_configuration)
end
|
#prepare_active_record_module ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/arfy/environment.rb', line 78
def prepare_active_record_module
class << ActiveRecord::Base
def establish_connection(configuration = nil)
end
def configurations
Rails.application.config.database_configuration
end
end
end
|
#set_rails_env(target) ⇒ Object
90
91
92
93
94
|
# File 'lib/arfy/environment.rb', line 90
def set_rails_env(target)
ENV['RAILS_ENV'] = (target || ENV["RAILS_ENV"]) || "development"
puts "working on environment: #{ENV['RAILS_ENV']}" if ENV["RAILS_ENV"]
ENV["RAILS_ENV"]
end
|