Class: Rays::Configuration
- Inherits:
-
Object
- Object
- Rays::Configuration
- Defined in:
- lib/rays/config/configuration.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
-
#environment ⇒ Object
Get current environment.
-
#environment=(environment_name) ⇒ Object
Set environment.
-
#environments ⇒ Object
Get list of environments.
-
#initialize ⇒ Configuration
constructor
Create Configuration object.
-
#mvn ⇒ Object
Get maven command.
-
#point(dir, name) ⇒ Object
Remember a point.
-
#project_root ⇒ Object
Get project root or throw an exception if invoked outside of a project.
-
#remove_point(name) ⇒ Object
Remove a point.
-
#scp ⇒ Object
Get secure copy command.
Constructor Details
#initialize ⇒ Configuration
Create Configuration object
32 33 34 35 36 37 38 |
# File 'lib/rays/config/configuration.rb', line 32 def initialize @debug = false @silent = false $global_config_path ||= "#{ENV['HOME']}/.rays_config" @global_config_file = nil load_config end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
27 28 29 |
# File 'lib/rays/config/configuration.rb', line 27 def points @points end |
Instance Method Details
#environment ⇒ Object
Get current environment
51 52 53 54 55 |
# File 'lib/rays/config/configuration.rb', line 51 def environment project_root # check if it's inside a project dir raise RaysException.new("no environment is configured. see: config/environment.yml.") if @environment.nil? @environment end |
#environment=(environment_name) ⇒ Object
Set environment
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rays/config/configuration.rb', line 60 def environment=(environment_name) if environments.include?(environment_name) yaml_file = get_dot_rays_file yaml_file.properties['environment'] = environment_name yaml_file.write Core.instance.reload else raise RaysException.new("cannot find environment <!#{environment_name}!>") end end |
#environments ⇒ Object
Get list of environments
74 75 76 77 78 |
# File 'lib/rays/config/configuration.rb', line 74 def environments project_root # check if it's inside a project dir raise RaysException.new("no environment is configured. see: config/environment.yml.") if @environments.nil? @environments end |
#mvn ⇒ Object
Get maven command
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rays/config/configuration.rb', line 105 def mvn save = false begin check_command(@mvn, 'Apache Maven', '-v') rescue RaysException => e save = true $log.error(e) @mvn = $terminal.ask('please provide the path to mvn executable: ') retry end if save get_global_config.properties['mvn_cmd'] = @mvn get_global_config.write end @mvn end |
#point(dir, name) ⇒ Object
Remember a point
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rays/config/configuration.rb', line 127 def point(dir, name) unless Dir.exist?(dir) raise RaysException.new("Cannot remember a point to a directory which does not exist. directory: <!#{dir}!>") end global_config = get_global_config global_config.properties['points'] = Hash.new if global_config.properties['points'].nil? point_name = name point_name ||= 'default' global_config.properties['points'][point_name] = dir global_config.write end |
#project_root ⇒ Object
Get project root or throw an exception if invoked outside of a project
43 44 45 46 |
# File 'lib/rays/config/configuration.rb', line 43 def project_root raise RaysException.new("Cannot find project root.") if @project_root.nil? or @project_root.empty? @project_root end |
#remove_point(name) ⇒ Object
Remove a point
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/rays/config/configuration.rb', line 143 def remove_point(name) global_config = get_global_config global_config.properties['points'] = Hash.new if global_config.properties['points'].nil? point_name = name point_name ||= 'default' if global_config.properties['points'].nil? or global_config.properties['points'][point_name].nil? raise RaysException.new("#{name} point does not exist") end global_config.properties['points'].delete point_name global_config.write end |
#scp ⇒ Object
Get secure copy command
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rays/config/configuration.rb', line 83 def scp save = false begin check_command(@scp, 'usage: scp') rescue RaysException => e save = true $log.error(e) @scp = $terminal.ask('please provide the path to scp executable: ') retry end if save get_global_config.properties['scp_cmd'] = @scp get_global_config.write end @scp end |