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
# File 'lib/config_loader/base.rb', line 8

def initialize file_path, options = {}
	@path 		 	= File.dirname file_path
	@file_name 	= File.basename file_path			
	parts 			= file_name.split(/(ya?ml$)/)
	name 				= parts.first
	@ext 			 	= parts.last
	@locale 		= options[:locale]

	@file_path 	= @locale ? File.join(@path, "#{@name}.#{@locale}.#{@ext}") : file_path

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



24
25
26
# File 'lib/config_loader/base.rb', line 24

def as_hash
	@as_hash ||= mashie
end

#load(*args) ⇒ Object



28
29
# File 'lib/config_loader/base.rb', line 28

def load *args
end