Class: Enginery::Configurator
- Inherits:
-
Object
- Object
- Enginery::Configurator
show all
- Includes:
- Helpers
- Defined in:
- lib/enginery/configurator.rb
Instance Method Summary
collapse
Methods included from Helpers
#activerecord_associations, #app_config, #app_controllers, #app_models, #boot_app, #controller_exists?, #datamapper_associations, #dst_path, extract_setup, fail, #fail_unless_in_app_folder!, fail_verbosely, #in_app_folder?, #load_boot_rb, #migrations_by_model, #model_exists?, o, parse_input, #routes_by_controller, #sequel_associations, #src_path, #unrootify, #valid_controller?, valid_db_type?, valid_engine?, valid_orm?, #valid_route?, valid_server?, validate_constant_name, #validate_route_name, #view_setups_for
Constructor Details
#initialize(dst_root, setups = {}, &proc) ⇒ Configurator
Returns a new instance of Configurator.
5
6
7
8
9
|
# File 'lib/enginery/configurator.rb', line 5
def initialize dst_root, setups = {}, &proc
@dst_root, @setups = dst_root, setups||{}
@setups.is_a?(Hash) || fail('setups should be a Hash. A %s given instead' % @setups.class)
self.instance_exec(&proc) if block_given?
end
|
Instance Method Details
#update_boot_rb ⇒ Object
88
89
|
# File 'lib/enginery/configurator.rb', line 88
def update_boot_rb
end
|
#update_config_yml ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/enginery/configurator.rb', line 11
def update_config_yml
setups = normalize_setups(@setups)
setups.delete 'db'
engine = setups['engine'] || EConstants::VIEW__DEFAULT_ENGINE_NAME
path = src_path(:layouts, engine)
if File.directory?(path)
Dir[path + '/*'].each {|f| FileUtils.cp(f, dst_path.views)}
setups['layout'] = 'layout'
end
return if setups.empty?
yml = YAML.load File.read(dst_path.config_yml)
ENVIRONMENTS.each do |env|
(cfg = yml[env] || yml[env.to_s]) && cfg.update(setups)
end
o
write_file dst_path.config_yml, YAML.dump(yml)
output_source_code YAML.dump(setups).split("\n")
end
|
#update_database_rb ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/enginery/configurator.rb', line 91
def update_database_rb
if orm = @setups[:orm]
source_file = src_path(:database, '%s.rb' % orm)
source_code = File.readlines(source_file)
o
update_file dst_path.database_rb, source_code
output_source_code(source_code)
end
end
|
#update_database_yml ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/enginery/configurator.rb', line 101
def update_database_yml
setups = normalize_setups(@setups[:db])
type = setups['type'] || DEFAULT_DB_TYPE
yml = YAML.load File.read(src_path(:database, '%s.yml' % type))
ENVIRONMENTS.each do |env|
(cfg = yml[env] || yml[env.to_s]) && cfg.update(setups)
end
o
write_file dst_path.database_yml, YAML.dump(yml)
setups['pass'] = '___________' if setups['pass']
output_source_code(YAML.dump(setups).split("\n")) if setups.any?
end
|
#update_gemfile ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/enginery/configurator.rb', line 34
def update_gemfile
return if @setups.empty?
gems, gemfiles = [], []
target_gems = File.file?(dst_path.Gemfile) ?
(File.read dst_path.Gemfile) : []
@setups.values_at(:orm, :engine, :server).compact.each do |klass|
gemfiles << [src_path(:gemfiles, '%s.rb' % klass), klass]
end
if orm = @setups[:orm]
db_type = (@setups[:db]||{})[:type] || DEFAULT_DB_TYPE
gemfiles << [src_path(:gemfiles, db_type, '%s.rb' % orm)]
end
gemfiles.each do |(gemfile,gem)|
if File.file?(gemfile)
File.readlines(gemfile).each do |l|
(l).each do |g|
gems << l.chomp unless target_gems.include?(g)
end
end
else
next unless gem
gem = class_to_gem(gem)
gems << ("gem '%s'" % gem) unless target_gems.include?(gem)
end
end
return if gems.empty?
o
source_code = ['', *gems, '']
update_file dst_path.Gemfile, source_code.join("\n")
output_source_code source_code
end
|
#update_rakefile ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/enginery/configurator.rb', line 68
def update_rakefile
test_framework = @setups[:test_framework] || DEFAULT_TEST_FRAMEWORK
source_file = src_path(:rakefiles, "#{test_framework}.rb")
unless File.file?(source_file)
o("%s not in the list of supported test frameworks: %s" % [
test_framework,
Dir[src_path(:rakefiles, '*.rb')].map {|f| f.sub(/\.rb\Z/, '')}*', '
])
end
source_code = File.readlines(source_file)
if orm = @setups[:orm]
source_file = src_path(:rakefiles, '%s.rb' % orm)
source_code.concat File.readlines(source_file)
end
o
update_file dst_path.Rakefile, source_code
output_source_code(source_code)
end
|