Class: Asetus
- Inherits:
-
Object
- Object
- Asetus
- 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
-
#cfg ⇒ Object
readonly
Returns the value of attribute cfg.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#system ⇒ Object
Returns the value of attribute system.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #from_json(json) ⇒ Object
- #from_yaml(yaml) ⇒ Object
- #load(level = :all) ⇒ Object
- #save(level = :user) ⇒ Object
- #to_json(config) ⇒ Object
- #to_yaml(config) ⇒ Object
Instance Attribute Details
#cfg ⇒ Object (readonly)
Returns the value of attribute cfg.
12 13 14 |
# File 'lib/asetus.rb', line 12 def cfg @cfg end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
12 13 14 |
# File 'lib/asetus.rb', line 12 def default @default end |
#system ⇒ Object
Returns the value of attribute system.
13 14 15 |
# File 'lib/asetus.rb', line 13 def system @system end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'lib/asetus.rb', line 13 def user @user end |
Class Method Details
.cfg(*args) ⇒ Object
16 17 18 |
# File 'lib/asetus.rb', line 16 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
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/asetus.rb', line 21 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
35 36 37 38 39 40 41 |
# File 'lib/asetus.rb', line 35 def save level=:user if level == :user save_cfg @usrdir, @user elsif level == :system save_cfg @sysdir, @system end end |