Class: Rays::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/config/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Create Configuration object



32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

  init_global_config

  init_project_root
  unless @project_root.nil?
    load_project_config
  end
end

Instance Attribute Details

#pointsObject (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

#environmentObject

Get current environment

Raises:



57
58
59
60
61
# File 'lib/rays/config/configuration.rb', line 57

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



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rays/config/configuration.rb', line 66

def environment=(environment_name)
  project_root # check if it's inside a project dir
  if environments.include?(environment_name)
    yaml_file = get_profile_file
    yaml_file.properties['environment'] = environment_name
    yaml_file.write
    Core.instance.reload
  else
    raise RaysException.new("cannot find environment <!#{environment_name}!>")
  end
end

#environmentsObject

Get list of environments

Raises:



81
82
83
84
85
# File 'lib/rays/config/configuration.rb', line 81

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

#mvnObject

Get maven command



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rays/config/configuration.rb', line 112

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



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/rays/config/configuration.rb', line 134

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_rootObject

Get project root or throw an exception if invoked outside of a project

Raises:



49
50
51
52
# File 'lib/rays/config/configuration.rb', line 49

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



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rays/config/configuration.rb', line 150

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

#scpObject

Get secure copy command



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rays/config/configuration.rb', line 90

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