Class: Asetus
- Inherits:
-
Object
show all
- Defined in:
- lib/asetus.rb,
lib/asetus/adapter/json.rb,
lib/asetus/adapter/yaml.rb,
lib/asetus/configstruct.rb
Defined Under Namespace
Classes: Adapter, ConfigStruct
Constant Summary
collapse
- CONFIG_FILE =
'config'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#cfg ⇒ Object
Returns the value of attribute cfg.
11
12
13
|
# File 'lib/asetus.rb', line 11
def cfg
@cfg
end
|
#default ⇒ Object
Returns the value of attribute default.
11
12
13
|
# File 'lib/asetus.rb', line 11
def default
@default
end
|
#system ⇒ Object
Returns the value of attribute system.
12
13
14
|
# File 'lib/asetus.rb', line 12
def system
@system
end
|
#user ⇒ Object
Returns the value of attribute user.
12
13
14
|
# File 'lib/asetus.rb', line 12
def user
@user
end
|
Class Method Details
.cfg(*args) ⇒ Object
15
16
17
|
# File 'lib/asetus.rb', line 15
def cfg *args
new(*args).cfg
end
|
Instance Method Details
#from_json(json) ⇒ Object
7
8
9
|
# File 'lib/asetus/adapter/json.rb', line 7
def from_json json
Adapter::JSON.from json
end
|
#from_yaml(yaml) ⇒ Object
7
8
9
|
# File 'lib/asetus/adapter/yaml.rb', line 7
def from_yaml yaml
Adapter::YAML.from yaml
end
|
#load(level = :all) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/asetus.rb', line 20
def load level=:all
if level == :default or level == :all
@cfg = merge @cfg, @default
end
if level == :system or level == :all
@system = load_cfg @sysdir
@cfg = merge @cfg, @system
end
if level == :user or level == :all
@user = load_cfg @usrdir
@cfg = merge @cfg, @user
end
end
|
#save(level = :user) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/asetus.rb', line 34
def save level=:user
if level == :user
save_cfg @usrdir, @user
elsif level == :system
save_cfg @sysdir, @system
end
end
|
#to_json(config) ⇒ Object
3
4
5
|
# File 'lib/asetus/adapter/json.rb', line 3
def to_json config
Adapter::JSON.to config._asetus_to_hash
end
|
#to_yaml(config) ⇒ Object
3
4
5
|
# File 'lib/asetus/adapter/yaml.rb', line 3
def to_yaml config
Adapter::YAML.to config._asetus_to_hash
end
|