class ConfigLoader::Base

Attributes

ext[R]
file_name[R]
file_path[R]
locale[R]
path[R]
root[R]

Public Class Methods

new(file_path, options = {}) click to toggle source

will try root element if such exists

# File lib/config_loader/base.rb, line 8
def initialize file_path, options = {}                        
        @path                     = File.dirname file_path
        @file_name   = File.basename file_path                        

        name                                 = parts.first.sub(/\.$/, '')
        @ext                              = parts.last
        @locale              = options[:locale] unless blank?(options[: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                                 = options[:dir] if options[:dir]
        @root                     = (options[: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

Public Instance Methods

as_hash() click to toggle source
# File lib/config_loader/base.rb, line 32
def as_hash
        @as_hash ||= mashie
end
load(*args) click to toggle source
# File lib/config_loader/base.rb, line 36
def load *args
end

Protected Instance Methods

blank?(obj) click to toggle source
# File lib/config_loader/base.rb, line 49
def blank? obj
        !obj || obj.empty?
end
config_file_path() click to toggle source
# File lib/config_loader/base.rb, line 65
def config_file_path
    @config_file_path ||= File.join(Rails.root.to_s, dir, file_path)
end
dir() click to toggle source
# File lib/config_loader/base.rb, line 57
def dir
        @dir ||= 'config'
end
file_content() click to toggle source
# File lib/config_loader/base.rb, line 53
def file_content
        File.open(config_file_path)
end
mashie() click to toggle source
# File lib/config_loader/base.rb, line 61
def mashie
        @mashie ||= ::Hashie::Mash.new content
end
parts() click to toggle source
# File lib/config_loader/base.rb, line 41
def parts
  @parts ||= file_name.split(/(#{reg_ext_format})$/)
end
path?(file_path) click to toggle source
# File lib/config_loader/base.rb, line 45
def path? file_path
  file_path.kind_of?(String) && file_path =~ /\.#{reg_ext_format}/
end