0.0
No commit activity in last 3 years
No release in over 3 years
Settings container, supporting nested settings
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.8.3
~> 3.12

Runtime

>= 0.8.1
 Project Readme

ModalSettings¶ ↑

Settings container, supporting nested settings.

Properties can be set from a hash with either String or Symbol keys.

s = Settings[:a=>1, 'b'=>2]

Properties can be accessed as attributes or as indices (String or Symbol).

puts s.a
puts s[:a]
puts s['a']

Properties are writable

s.a = 100
s[:a] = 100
s['a'] = 100

Nested hashes are accessed as Settings too.

s = Setings[:a=>1, :email=>{:from=>'a', :to=>'b'}]
puts s.email.a

Can be converted to a Hash

puts s.to_h.inspect

Converts to YAML as a Hash

puts s.to_yaml

Undefined parameters can be read (and return nil)

puts s.x

Settings can be merged

s2 = s.merge(:z=>100)

Note that properties with names corresponding to Object methods cannot be accessed with the s.x syntax:

s = Settings[:object_id=>100]
puts s.object_id   # this is not the setting!
puts s[:object_id] # => 100
s.object_id = 200  # this changes the setting
puts s[:object_id] # => 200

To know which current settings need s[] syntax use the collisions method:

s = Settings[:object_id=>1]
s.collisions # [:object_id]

To check for collisions recursively:

s = Settings[:object_id=>{:to_h=>1, :x=>2}]
s.collisions(true) # [:object_id, [:object_id, :to_h]]

Copyright © 2012 Javier Goizueta. See LICENSE.txt for further details.