Class: D13n::Configuration::DefaultSource
- Inherits:
-
Object
- Object
- D13n::Configuration::DefaultSource
- Extended by:
- Forwardable
- Defined in:
- lib/d13n/configuration/default_source.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
Class Method Summary collapse
- .config_path ⇒ Object
- .config_search_paths ⇒ Object
- .convert_to_list(value) ⇒ Object
- .defaults ⇒ Object
- .defaults=(default_config) ⇒ Object
- .transform_for(key) ⇒ Object
Instance Method Summary collapse
- #default_alias ⇒ Object
- #default_values ⇒ Object
- #frozen_default ⇒ Object
-
#initialize ⇒ DefaultSource
constructor
A new instance of DefaultSource.
Constructor Details
#initialize ⇒ DefaultSource
Returns a new instance of DefaultSource.
23 24 25 26 27 |
# File 'lib/d13n/configuration/default_source.rb', line 23 def initialize frozen_default @defaults = default_values @alias = default_alias end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
17 18 19 |
# File 'lib/d13n/configuration/default_source.rb', line 17 def alias @alias end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
17 18 19 |
# File 'lib/d13n/configuration/default_source.rb', line 17 def defaults @defaults end |
Class Method Details
.config_path ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/d13n/configuration/default_source.rb', line 77 def self.config_path Proc.new { found_path = D13n.config[:config_search_paths].detect do |file| File.(file) if File.exist? file end found_path || "" } end |
.config_search_paths ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/d13n/configuration/default_source.rb', line 57 def self.config_search_paths Proc.new { paths = [ File.join("config", "#{D13n.app_name}.yml"), File.join("#{D13n.app_name}.yml") ] if D13n.service.instance.root paths << File.join(D13n.service.instance.root, "config", "#{D13n.app_name}.yml") paths << File.join(D13n.service.instance.root, "#{D13n.app_name}.yml") end if ENV["HOME"] paths << File.join(ENV["HOME"], ".#{D13n.app_name}", "#{D13n.app_name}.yml") paths << File.join(ENV["HOME"], "#{D13n.app_name}.yml") end paths } end |
.convert_to_list(value) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/d13n/configuration/default_source.rb', line 91 def self.convert_to_list(value) case value when String value.split(/\s*,\s*/) when Array value else raise ArgumentError.new("Config value '#{value}' couldn't be turned into a list.") end end |
.defaults ⇒ Object
49 50 51 |
# File 'lib/d13n/configuration/default_source.rb', line 49 def self.defaults D13n::Configuration::DEFAULTS end |
.defaults=(default_config) ⇒ Object
53 54 55 |
# File 'lib/d13n/configuration/default_source.rb', line 53 def self.defaults=(default_config) D13n::Configuration::DEFAULTS.merge!(default_config) end |
.transform_for(key) ⇒ Object
86 87 88 89 |
# File 'lib/d13n/configuration/default_source.rb', line 86 def self.transform_for(key) default_settings = D13n::Configuration::DEFAULTS[key] default_settings[:transform] if default_settings end |
Instance Method Details
#default_alias ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/d13n/configuration/default_source.rb', line 41 def default_alias result = {} D13n::Configuration::DEFAULTS.each do |key,value| result[key] = (value[:alias] || key).to_s end result end |
#default_values ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/d13n/configuration/default_source.rb', line 33 def default_values result = {} D13n::Configuration::DEFAULTS.each do |key, value| result[key] = value[:default] end result end |
#frozen_default ⇒ Object
29 30 31 |
# File 'lib/d13n/configuration/default_source.rb', line 29 def frozen_default D13n::Configuration::DEFAULTS.freeze end |