Class: PyramidScheme::Configuration
- Inherits:
-
Object
- Object
- PyramidScheme::Configuration
- Defined in:
- lib/pyramid_scheme/configuration.rb
Constant Summary collapse
- INDEX_FILE_EXTENSIONS =
[ '.spa', '.spd', '.sph', '.spi', '.spm', '.spp', '.spk' ]
Class Method Summary collapse
- .defaults ⇒ Object
- .recursive_const_get(klass_str, mod_base = Kernel) ⇒ Object
- .set {|configatron.pyramid_scheme| ... } ⇒ Object
- .set_from_yml(path) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 16 17 18 19 |
# File 'lib/pyramid_scheme/configuration.rb', line 13 def initialize( = {}) self.class.set do |config| .each do |key, value| config.send("#{key}=", value) end end end |
Class Method Details
.defaults ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/pyramid_scheme/configuration.rb', line 43 def self.defaults { :lock_file_name => 'pyramid_scheme_index_in_progress.txt', :index_provider_class => PyramidScheme::IndexProvider::FileSystem, :indexer_class => PyramidScheme::Indexer::ThinkingSphinx, :permit_server_daemon => true } end |
.recursive_const_get(klass_str, mod_base = Kernel) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/pyramid_scheme/configuration.rb', line 56 def self.recursive_const_get(klass_str, mod_base = Kernel) first_namespace = klass_str[/^\w*\:\:/] if first_namespace.nil? mod_base.const_get(klass_str) else recursive_const_get(klass_str.gsub(first_namespace, ""), mod_base.const_get(first_namespace[0..-3])) end end |
.set {|configatron.pyramid_scheme| ... } ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/pyramid_scheme/configuration.rb', line 21 def self.set(&block) self.defaults.each do |key, value| if configatron.pyramid_scheme.send("#{key}").nil? || configatron.pyramid_scheme.send("#{key}") == "" configatron.pyramid_scheme.send("#{key}=", value) end end yield(configatron.pyramid_scheme) end |
.set_from_yml(path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pyramid_scheme/configuration.rb', line 30 def self.set_from_yml(path) config_hash = YAML::load(File.open(path)) set do |config| config_hash.each do |key, value| if key =~ /class$/ config.send("#{key}=", recursive_const_get(value)) else config.send("#{key}=", value) end end end end |
Instance Method Details
#[](key) ⇒ Object
52 53 54 |
# File 'lib/pyramid_scheme/configuration.rb', line 52 def [](key) configatron.pyramid_scheme.to_hash[key] end |