Class: Configue::Setting
- Inherits:
-
Object
show all
- Defined in:
- lib/configue/setting.rb
Instance Method Summary
collapse
Constructor Details
#initialize(owner_class) ⇒ Setting
Returns a new instance of Setting.
9
10
11
12
|
# File 'lib/configue/setting.rb', line 9
def initialize(owner_class)
@owner = owner_class
@loader = YamlLoader.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/configue/setting.rb', line 88
def method_missing(name, *args, &block)
access_name = @owner.config_method_name
return super unless access_name
instance = self.load!
if instance[access_name]
instance[access_name].__send__(name, *args, &block)
else
super
end
end
|
Instance Method Details
#base_namespace(key = nil) ⇒ Object
14
15
16
17
|
# File 'lib/configue/setting.rb', line 14
def base_namespace(key=nil)
@base_namespace = key if key
@base_namespace
end
|
#base_namespace=(key) ⇒ Object
19
20
21
|
# File 'lib/configue/setting.rb', line 19
def base_namespace=(key)
base_namespace(key)
end
|
#load! ⇒ Object
67
68
69
|
# File 'lib/configue/setting.rb', line 67
def load!
@owner.instance ? @owner.instance : @owner.new_container(load_sources)
end
|
#namespace(key = nil) ⇒ Object
23
24
25
26
|
# File 'lib/configue/setting.rb', line 23
def namespace(key=nil)
@namespace = key if key
@namespace
end
|
#namespace=(key) ⇒ Object
28
29
30
|
# File 'lib/configue/setting.rb', line 28
def namespace=(key)
namespace(key)
end
|
#source_dir(*dirs) ⇒ Object
32
33
34
35
36
|
# File 'lib/configue/setting.rb', line 32
def source_dir(*dirs)
@sources ||= []
@sources += dirs.map {|d| {dir: d}} unless dirs.empty?
@sources
end
|
#source_dir=(dir) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/configue/setting.rb', line 38
def source_dir=(dir)
if dir.is_a?(Array)
source_dir(*dir)
else
source_dir(dir)
end
end
|
#source_file(*files) ⇒ Object
Specifies files that you want to load into your class.
You can call this method many times.
Arguments
53
54
55
56
57
|
# File 'lib/configue/setting.rb', line 53
def source_file(*files)
@sources ||= []
@sources += files.map {|f| {file: f}} unless files.empty?
@sources
end
|
#source_file=(file) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/configue/setting.rb', line 59
def source_file=(file)
if file.is_a?(Array)
source_file(*file)
else
source_file(file)
end
end
|