Class: ConfigLoader::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/config_loader/base.rb

Direct Known Subclasses

Json, Yaml

Instance Attribute Summary collapse

Instance Method Summary collapse

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, 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

Instance Attribute Details

#extObject (readonly)

Returns the value of attribute ext.



5
6
7
# File 'lib/config_loader/base.rb', line 5

def ext
  @ext
end

#file_nameObject (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_pathObject (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

#localeObject (readonly)

Returns the value of attribute locale.



5
6
7
# File 'lib/config_loader/base.rb', line 5

def locale
  @locale
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/config_loader/base.rb', line 5

def path
  @path
end

#rootObject (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_hashObject



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