class ThinkingSphinx::Settings
Constants
- ALWAYS_ABSOLUTE
- DEFAULTS
- FILE_KEYS
Attributes
configuration[R]
Public Class Methods
call(configuration)
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 24 def self.call(configuration) new(configuration).call end
new(configuration)
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 28 def initialize(configuration) @configuration = configuration end
Public Instance Methods
call()
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 32 def call return defaults unless File.exists? file merged.inject({}) do |hash, (key, value)| if absolute_key?(key) hash[key] = absolute value else hash[key] = value end hash end end
Private Instance Methods
absolute(relative)
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 51 def absolute(relative) return relative if relative.nil? real_path File.absolute_path(relative, framework.root) end
absolute_key?(key)
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 57 def absolute_key?(key) return true if ALWAYS_ABSOLUTE.include?(key) merged["absolute_paths"] && file_keys.include?(key) end
defaults()
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 63 def defaults DEFAULTS.inject({}) do |hash, (key, value)| value = value.gsub("ENVIRONMENT", framework.environment) if FILE_KEYS.include?(key) hash[key] = absolute value else hash[key] = value end hash end end
file()
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 77 def file @file ||= Pathname.new(framework.root).join "config", "thinking_sphinx.yml" end
file_keys()
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 81 def file_keys @file_keys ||= FILE_KEYS + (original["file_keys"] || []) end
join(first, last)
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 85 def join(first, last) return first if last.nil? File.join first, last end
merged()
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 91 def merged @merged ||= defaults.merge original end
original()
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 95 def original input = File.read file input = ERB.new(input).result if defined?(ERB) contents = YAML.load input contents && contents[framework.environment] || {} end
real_path(base, nonexistent = nil)
click to toggle source
# File lib/thinking_sphinx/settings.rb, line 103 def real_path(base, nonexistent = nil) if File.exist?(base) join File.realpath(base), nonexistent else components = File.split base real_path components.first, join(components.last, nonexistent) end end