Class: Chef::SolrInstaller::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/solr/solr_installer.rb

Defined Under Namespace

Modules: CLI Classes: CompatConfig

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



130
131
132
# File 'lib/chef/solr/solr_installer.rb', line 130

def initialize
  apply_hash(self.class.default_values)
end

Class Method Details

.configurable(value, default = nil) ⇒ Object



67
68
69
70
71
# File 'lib/chef/solr/solr_installer.rb', line 67

def self.configurable(value, default=nil)
  configurables << value
  attr_accessor value
  default_values[value] = default if default
end

.configurablesObject



63
64
65
# File 'lib/chef/solr/solr_installer.rb', line 63

def self.configurables
  @configurables ||= []
end

.default_valuesObject



59
60
61
# File 'lib/chef/solr/solr_installer.rb', line 59

def self.default_values
  @default_values ||= {}
end

Instance Method Details

#apply_hash(hash) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/chef/solr/solr_installer.rb', line 153

def apply_hash(hash)
  hash.each do |key, value|
    method_for_key = "#{key}=".to_sym
    if respond_to?(method_for_key)
      send(method_for_key, value)
    else
      STDERR.puts("Configuration setting #{key} is unknown and will be ignored")
    end
  end
end

#configure_from(argv) ⇒ Object



134
135
136
137
138
139
140
141
142
143
# File 'lib/chef/solr/solr_installer.rb', line 134

def configure_from(argv)
  cli_config = CLI.parse_options(argv)
  #pp :cli_config => cli_config.to_hash
  config_file_config = CompatConfig.new.from_file(cli_config.config_file).to_hash
  #pp :config_file_config => config_file_config
  apply_hash(config_file_config)
  apply_hash(cli_config.to_hash)
  #pp :combined_config => self.to_hash
  self
end

#each_configurableObject



73
74
75
76
77
# File 'lib/chef/solr/solr_installer.rb', line 73

def each_configurable
  self.class.configurables.each do |config_param|
    yield [config_param, send(config_param)]
  end
end

#solr_base_pathObject



84
85
86
# File 'lib/chef/solr/solr_installer.rb', line 84

def solr_base_path
  @solr_base_path || '/var/chef'
end

#solr_base_path=(base_path) ⇒ Object

Sets the solr_base_path. Also resets solr_home_path, solr_jetty_path, and solr_data_path.



90
91
92
93
# File 'lib/chef/solr/solr_installer.rb', line 90

def solr_base_path=(base_path)
  @solr_home_path, @solr_jetty_path, @solr_data_path = nil,nil,nil
  @solr_base_path = base_path
end

#solr_data_pathObject



113
114
115
# File 'lib/chef/solr/solr_installer.rb', line 113

def solr_data_path
  @solr_data_path || File.join(solr_base_path, 'solr', 'data')
end

#solr_home_pathObject



99
100
101
# File 'lib/chef/solr/solr_installer.rb', line 99

def solr_home_path
  @solr_home_path || File.join(solr_base_path, 'solr')
end

#solr_jetty_pathObject



106
107
108
# File 'lib/chef/solr/solr_installer.rb', line 106

def solr_jetty_path
  @solr_jetty_path || File.join(solr_base_path, 'solr-jetty')
end

#to_hashObject



145
146
147
148
149
150
151
# File 'lib/chef/solr/solr_installer.rb', line 145

def to_hash
  self.class.configurables.inject({}) do |hash, config_option|
    value = instance_variable_get("@#{config_option}".to_sym)
    hash[config_option] = value if value
    hash
  end
end