Class: SaltedRails::Config
- Inherits:
-
Object
- Object
- SaltedRails::Config
- Defined in:
- lib/salted-rails/config.rb
Instance Attribute Summary collapse
-
#admin_password ⇒ Object
Returns the value of attribute admin_password.
-
#box ⇒ Object
Returns the value of attribute box.
-
#ca_path ⇒ Object
Returns the value of attribute ca_path.
-
#copy_from_home ⇒ Object
Returns the value of attribute copy_from_home.
-
#databases ⇒ Object
Returns the value of attribute databases.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#files ⇒ Object
Returns the value of attribute files.
-
#forward_agent ⇒ Object
Returns the value of attribute forward_agent.
-
#gems ⇒ Object
Returns the value of attribute gems.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#machine ⇒ Object
Returns the value of attribute machine.
-
#machines ⇒ Object
Returns the value of attribute machines.
-
#mapped_ports ⇒ Object
Returns the value of attribute mapped_ports.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#mirror ⇒ Object
Returns the value of attribute mirror.
-
#packages ⇒ Object
Returns the value of attribute packages.
-
#ports ⇒ Object
Returns the value of attribute ports.
-
#private_key_path ⇒ Object
Returns the value of attribute private_key_path.
-
#rails_root ⇒ Object
Returns the value of attribute rails_root.
-
#region ⇒ Object
Returns the value of attribute region.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#salt_root ⇒ Object
Returns the value of attribute salt_root.
-
#sync_vagrant ⇒ Object
Returns the value of attribute sync_vagrant.
-
#versions ⇒ Object
Returns the value of attribute versions.
-
#web_password ⇒ Object
Returns the value of attribute web_password.
Instance Method Summary collapse
-
#clone ⇒ Object
Clone.
- #configure_vagrant(config) ⇒ Object
- #define(machine) {|obj| ... } ⇒ Object
- #gui? ⇒ Boolean
-
#initialize(rails_root, machine = 'default') ⇒ Config
constructor
pass vm.ui for the logger if you want debugging info.
- #normalize ⇒ Object
- #sanitize_dns_name(name) ⇒ Object
- #to_hash ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(rails_root, machine = 'default') ⇒ Config
pass vm.ui for the logger if you want debugging info
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/salted-rails/config.rb', line 42 def initialize(rails_root, machine = 'default') @logger = Log4r::Logger.new("vagrant::salted-rails") @machine = machine @rails_root = rails_root @rails_root += '/' unless @rails_root =~ /\/$/ @salt_root = nil # see salt/vagrant/top.sls for other roles @roles = %w{ app web db } @domain = nil @admin_password = nil @web_password = nil @private_key_path = nil @mirror = nil @memory = nil @ports = [ 80, 443, 880, 3000 ] @mapped_ports = { } @sync_vagrant = nil @box = nil @ca_path = nil @region = nil @forward_agent = true @files = [ '.ruby-version', '.java-version', '.php-version', 'config/database.yml', 'Gemfile', 'Gemfile.lock' ].select{ |f| File.exist?(@rails_root + f) } @packages = nil @copy_from_home = [ ] ENV['REMOTE_MACHINE'] = 'true' database_file = @rails_root + 'config/database.yml' @databases = YAML.load(ERB.new(IO.read(database_file)).result) rescue { } ENV['REMOTE_MACHINE'] = nil @gems = { } if File.exists? @rails_root + 'Gemfile' File.foreach(@rails_root + 'Gemfile') do |line| if line =~ /^\s*gem\s*['"]([^'"]+)['"][,\s]*(['"]([^'"]+)['"])?/ gem = $1 version = $3.to_s version = true if version == '' or version !~ /\d/ @gems[gem] = version end end end @databases.each do |key, details| @gems[details['adapter']] ||= true end @roles << 'mysql' if @gems.include?('mysql') or @gems.include?('mysql2') @versions= { } @machines = [ ] @hostname = nil end |
Instance Attribute Details
#admin_password ⇒ Object
Returns the value of attribute admin_password.
13 14 15 |
# File 'lib/salted-rails/config.rb', line 13 def admin_password @admin_password end |
#box ⇒ Object
Returns the value of attribute box.
10 11 12 |
# File 'lib/salted-rails/config.rb', line 10 def box @box end |
#ca_path ⇒ Object
Returns the value of attribute ca_path.
11 12 13 |
# File 'lib/salted-rails/config.rb', line 11 def ca_path @ca_path end |
#copy_from_home ⇒ Object
Returns the value of attribute copy_from_home.
12 13 14 |
# File 'lib/salted-rails/config.rb', line 12 def copy_from_home @copy_from_home end |
#databases ⇒ Object
Returns the value of attribute databases.
15 16 17 |
# File 'lib/salted-rails/config.rb', line 15 def databases @databases end |
#domain ⇒ Object
Returns the value of attribute domain.
16 17 18 |
# File 'lib/salted-rails/config.rb', line 16 def domain @domain end |
#files ⇒ Object
Returns the value of attribute files.
17 18 19 |
# File 'lib/salted-rails/config.rb', line 17 def files @files end |
#forward_agent ⇒ Object
Returns the value of attribute forward_agent.
18 19 20 |
# File 'lib/salted-rails/config.rb', line 18 def forward_agent @forward_agent end |
#gems ⇒ Object
Returns the value of attribute gems.
19 20 21 |
# File 'lib/salted-rails/config.rb', line 19 def gems @gems end |
#hostname ⇒ Object
Returns the value of attribute hostname.
20 21 22 |
# File 'lib/salted-rails/config.rb', line 20 def hostname @hostname end |
#logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/salted-rails/config.rb', line 21 def logger @logger end |
#machine ⇒ Object
Returns the value of attribute machine.
22 23 24 |
# File 'lib/salted-rails/config.rb', line 22 def machine @machine end |
#machines ⇒ Object
Returns the value of attribute machines.
23 24 25 |
# File 'lib/salted-rails/config.rb', line 23 def machines @machines end |
#mapped_ports ⇒ Object
Returns the value of attribute mapped_ports.
28 29 30 |
# File 'lib/salted-rails/config.rb', line 28 def mapped_ports @mapped_ports end |
#memory ⇒ Object
Returns the value of attribute memory.
24 25 26 |
# File 'lib/salted-rails/config.rb', line 24 def memory @memory end |
#mirror ⇒ Object
Returns the value of attribute mirror.
25 26 27 |
# File 'lib/salted-rails/config.rb', line 25 def mirror @mirror end |
#packages ⇒ Object
Returns the value of attribute packages.
26 27 28 |
# File 'lib/salted-rails/config.rb', line 26 def packages @packages end |
#ports ⇒ Object
Returns the value of attribute ports.
27 28 29 |
# File 'lib/salted-rails/config.rb', line 27 def ports @ports end |
#private_key_path ⇒ Object
Returns the value of attribute private_key_path.
29 30 31 |
# File 'lib/salted-rails/config.rb', line 29 def private_key_path @private_key_path end |
#rails_root ⇒ Object
Returns the value of attribute rails_root.
30 31 32 |
# File 'lib/salted-rails/config.rb', line 30 def rails_root @rails_root end |
#region ⇒ Object
Returns the value of attribute region.
31 32 33 |
# File 'lib/salted-rails/config.rb', line 31 def region @region end |
#roles ⇒ Object
Returns the value of attribute roles.
32 33 34 |
# File 'lib/salted-rails/config.rb', line 32 def roles @roles end |
#salt_root ⇒ Object
Returns the value of attribute salt_root.
33 34 35 |
# File 'lib/salted-rails/config.rb', line 33 def salt_root @salt_root end |
#sync_vagrant ⇒ Object
Returns the value of attribute sync_vagrant.
34 35 36 |
# File 'lib/salted-rails/config.rb', line 34 def sync_vagrant @sync_vagrant end |
#versions ⇒ Object
Returns the value of attribute versions.
35 36 37 |
# File 'lib/salted-rails/config.rb', line 35 def versions @versions end |
#web_password ⇒ Object
Returns the value of attribute web_password.
14 15 16 |
# File 'lib/salted-rails/config.rb', line 14 def web_password @web_password end |
Instance Method Details
#clone ⇒ Object
Clone
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/salted-rails/config.rb', line 182 def clone obj = self.dup obj.roles = @roles.dup obj.ports = @ports.dup obj.files = @files.dup obj.copy_from_home = @copy_from_home.dup obj.databases = @databases.dup obj.gems = @gems.dup obj end |
#configure_vagrant(config) ⇒ Object
220 221 222 223 224 225 |
# File 'lib/salted-rails/config.rb', line 220 def configure_vagrant(config) require 'salted-rails/vagrant_helper' normalize helper = SaltedRails::VagrantHelper.new(self) helper.configure_vagrant(config) end |
#define(machine) {|obj| ... } ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/salted-rails/config.rb', line 172 def define(machine, &block) obj = self.clone obj.machine = machine obj.machines = [ ] obj.logger = @logger @machines << obj yield(obj) if block_given? end |
#gui? ⇒ Boolean
95 96 97 |
# File 'lib/salted-rails/config.rb', line 95 def gui? @roles.include? 'gui' end |
#normalize ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/salted-rails/config.rb', line 99 def normalize @versions['mysql'] ||= '5.5' if @roles.include?('mysql') @versions['teamcity'] ||= '8.0.4' if @roles.include?('teamcity') @versions['rubymine'] ||= '5.4.3' if @roles.include?('rubymine') @roles << 'gui' if @roles.include?('rubymine') and not @roles.include?('gui') %w{ ruby php java }.each do |lang| version = File.open(@rails_root + ".#{lang}-version", 'r') do |f_in| f_in.gets.gsub(/\s/,'') end rescue nil @versions[lang] ||= version if version end unless @versions.include?('ruby') File.open(@rails_root + '.rvmrc', 'r') do |f_in| while (line = f_in.gets) and not @versions.include('ruby') @versions['ruby'] = $1 if line =~ /^\s*environment_id=['"]([^"'@]+)/ end end rescue nil end if @memory.nil? @memory = 512 { 'gui' => 1536, 'teamcity' => 1536, 'cruisecontrolrb' => 512 }.each do |role, extra| @memory += extra if @roles.include?(role) end end if @domain.nil? if @hostname @domain = @hostname.sub(/^[^.]*\.?/, '') else @domain = sanitize_dns_name(File.basename(File.(@rails_root).sub(/\/$/, '').sub(/\/(app|site|web|www|website)\d*$/, ''))) + '.test' @domain = 'railsapp.test' if @domain == '.test' end end if @hostname.nil? or @hostname == '' if @machine == 'default' @hostname = @domain else @hostname = sanitize_dns_name(@machine.to_s) if @hostname == '' @hostname = @domain else @hostname <<= '.' + @domain end end end @private_key_path ||= '~/.ssh/id_rsa' @mirror ||= 'auto' @salt_root ||= File.dirname(__FILE__) + '/../../' @ca_path ||= '/etc/ssl/certs/ca-certificates.crt' @box ||= 'preciseCloud32' @ca_path = nil unless File.exist?(@ca_path) @region ||= 'San Francisco 1' { 'teamcity' => 8111, 'cruisecontrolrb' => 3333 }.each do |role, port| @ports << port if @roles.include?(role) and not @ports.include?(port) end @sync_vagrant = true if @sync_vagrant.nil? @machines.each {|m| m.normalize} end |
#sanitize_dns_name(name) ⇒ Object
37 38 39 |
# File 'lib/salted-rails/config.rb', line 37 def sanitize_dns_name(name) dns_name = name.downcase.gsub(/[^-0-9a-z]+/,'-').sub(/^-+/, '').sub(/-+$/, '') end |
#to_hash ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/salted-rails/config.rb', line 193 def to_hash { 'admin_password' => @admin_password, 'databases' => @databases, 'disable_vagrant_sync' => @disable_vagrant_sync, 'domain' => @domain, 'files' => @files, 'forward_agent' => @forward_agent, 'gems' => @gems, 'hostname' => @hostname, 'machine' => @machine, 'mapped_ports' => @mapped_ports, 'memory' => @memory, 'mirror' => @mirror, 'ports' => @ports, 'region' => @region, 'roles' => @roles, 'user_password' => @user_password, 'versions' => @versions } end |
#to_yaml ⇒ Object
215 216 217 218 |
# File 'lib/salted-rails/config.rb', line 215 def to_yaml normalize self.to_hash.to_yaml end |