Class: Confickle
- Inherits:
-
Object
- Object
- Confickle
- Defined in:
- lib/confickle.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#symbolize_names ⇒ Object
readonly
Returns the value of attribute symbolize_names.
Instance Method Summary collapse
- #content(*args) ⇒ Object (also: #contents)
-
#initialize(options) ⇒ Confickle
constructor
A new instance of Confickle.
- #json(*args) ⇒ Object
- #path(*args) ⇒ Object
- #yaml(*args) ⇒ Object
Constructor Details
#initialize(options) ⇒ Confickle
Returns a new instance of Confickle.
11 12 13 14 15 16 17 18 |
# File 'lib/confickle.rb', line 11 def initialize() if .is_a? String = {root: } end @root = File.absolute_path(.fetch(:root)) @symbolize_names = .fetch(:symbolize_names, true) end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/confickle.rb', line 9 def root @root end |
#symbolize_names ⇒ Object (readonly)
Returns the value of attribute symbolize_names.
9 10 11 |
# File 'lib/confickle.rb', line 9 def symbolize_names @symbolize_names end |
Instance Method Details
#content(*args) ⇒ Object Also known as: contents
25 26 27 |
# File 'lib/confickle.rb', line 25 def content(*args) File.read(self.path(*args)) end |
#json(*args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/confickle.rb', line 30 def json(*args) if args.last.is_a? Hash args = args.dup = args.pop else = {} end sn = .fetch(:symbolize_names, self.symbolize_names) JSON.parse( self.content(*args), symbolize_names: sn ) end |
#path(*args) ⇒ Object
21 22 23 |
# File 'lib/confickle.rb', line 21 def path(*args) File.join(self.root, *args) end |
#yaml(*args) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/confickle.rb', line 46 def yaml(*args) if args.last.is_a? Hash args = args.dup = args.pop else = {} end retval = YAML.load_file(path(*args)) sn = .fetch(:symbolize_names, self.symbolize_names) if sn RecSym.this(retval) else retval end end |