Class: ConfigLoader::Base
- Inherits:
-
Object
- Object
- ConfigLoader::Base
- Defined in:
- lib/config_loader/base.rb
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #as_hash ⇒ Object
-
#initialize(file_path, options = {}) ⇒ Base
constructor
will try root element if such exists.
- #load(*args) ⇒ Object
Constructor Details
#initialize(file_path, options = {}) ⇒ Base
will try root element if such exists
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/config_loader/base.rb', line 8 def initialize file_path, = {} @path = File.dirname file_path @file_name = File.basename file_path name = parts.first.sub(/\.$/, '') @ext = parts.last @locale = [:locale] unless blank?([:locale]) @file_path = file_path unless blank? @locale @file_name = [name, @locale, @ext].compact.join('.') @file_path = File.join(@path, @file_name) end @dir = '' if file_path[0] == '/' @dir = [:dir] if [:dir] @root = ([:root] || file_name.split('.').first).to_s @root = nil unless mashie.send(@root) @mashie = mashie.send(@root) if @root rescue NoMethodError # if no mashie @root = nil end |
Instance Attribute Details
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
5 6 7 |
# File 'lib/config_loader/base.rb', line 5 def ext @ext end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
5 6 7 |
# File 'lib/config_loader/base.rb', line 5 def file_name @file_name end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/config_loader/base.rb', line 5 def file_path @file_path end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
5 6 7 |
# File 'lib/config_loader/base.rb', line 5 def locale @locale end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/config_loader/base.rb', line 5 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/config_loader/base.rb', line 5 def root @root end |
Instance Method Details
#as_hash ⇒ Object
32 33 34 |
# File 'lib/config_loader/base.rb', line 32 def as_hash @as_hash ||= mashie end |
#load(*args) ⇒ Object
36 37 |
# File 'lib/config_loader/base.rb', line 36 def load *args end |