figly 1.0.0.beta.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 414f612efa27e5aa6f362061fec77f55958b85da
4
- data.tar.gz: 8ed5ca2a49ff04497a2f0fb07b2ead2d760d1e02
3
+ metadata.gz: 42364b75b7532c60705dbac8b6ef845d5c050fd1
4
+ data.tar.gz: 967175d1098a36cb2667ef092b3c5e9af0f681cf
5
5
  SHA512:
6
- metadata.gz: 8744a5d0c0e1e11a188ca326eb19672ff54f5c26e3165e11173022c3b7a992e73ad41be1d504dc12e50356a9f33d2198999e70e61103c511ac6a81e196ac6815
7
- data.tar.gz: 1ed7f7a1b1aa67326ce4f585e5041158c3aace92ea7dd4b03531792dbd2ba941f3d073c55ddff10242b33e85f687de1be282f8e88fbaf52f8b8b380e8007a9ae
6
+ metadata.gz: 55611aa6fd7c901dae7cb0d521840b7587f2273f1f14877cb225737a07d40a09cf7cc4f28a077182c18c41ba85f4100cf172cce29bfb543c9661b7ba42a82254
7
+ data.tar.gz: 40a0f3233a2544f8b95a3cc5a22560ddc96c46ce85c0609b021de7f3aa48d69eb3b0dffc43292aa5e067f1ae98420c0e9863aa9e80ba525699b00e58933109c0
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Figly::VERSION
9
9
  spec.authors = ["Ryan Canty"]
10
10
  spec.email = ["jrcanty@gmail.com"]
11
- spec.summary = %q{A tiny gem that allows you to access config settings from YAML}
11
+ spec.summary = %q{A tiny gem that allows you to access config settings from YAML, TOML, or JSON}
12
12
  spec.description = %q{If you ever wanted to access a config Hash using the dot operator, this is the gem for you.}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(spec)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "toml"
21
22
  spec.add_development_dependency "bundler", "~> 1.6"
22
23
  spec.add_development_dependency "rake"
23
24
  spec.add_development_dependency "pry"
@@ -1,13 +1,27 @@
1
1
  require "figly/version"
2
2
  require "figly/settings"
3
- module Figly
4
- @@path = nil unless defined? @@path
5
3
 
4
+ module Figly
6
5
  def self.setup(path)
7
- @@path = path
6
+ raise "File does not exist: #{path}" unless File.exists?(path)
7
+ ext = File.extname(path)
8
+ @@data = case ext
9
+ when '.toml'
10
+ require 'toml'
11
+ TOML.load_file(path)
12
+ when '.yml'
13
+ require 'yaml'
14
+ YAML.load_file(path)
15
+ when '.json'
16
+ require 'json'
17
+ JSON.parse(File.read(path))
18
+ else
19
+ raise "Unsupported file extension (#{ext})"
20
+ end
21
+ @@data
8
22
  end
9
23
 
10
- def self.path
11
- @@path
24
+ def self.data
25
+ @@data
12
26
  end
13
27
  end
@@ -1,4 +1,3 @@
1
- require 'yaml'
2
1
  module Figly
3
2
  module Settings
4
3
  module SettingsHash
@@ -12,13 +11,10 @@ module Figly
12
11
  end
13
12
  end
14
13
 
15
- def self.settings_hash
16
- YAML.load_file(Figly.path)
17
- end
18
-
19
14
  def self.method_missing(meth, *args, &block)
20
- if self.settings_hash.has_key? meth.to_s
21
- val = settings_hash[meth.to_s]
15
+ data = Figly.data
16
+ if data.has_key? meth.to_s
17
+ val = data[meth.to_s]
22
18
  if val.instance_of?(Hash)
23
19
  val.extend(SettingsHash)
24
20
  elsif val.instance_of? Array
@@ -1,3 +1,3 @@
1
1
  module Figly
2
- VERSION = "1.0.0.beta.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,37 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Figly do
4
- before do
5
- Figly.setup(config_file)
6
- end
4
+ context 'YAML' do
5
+ before do
6
+ Figly.setup(config_file)
7
+ end
7
8
 
8
- it 'should set path properly' do
9
- expect(Figly.path).to include('config.yml')
10
- end
11
-
12
- it 'should correctly access and integer on the top level' do
13
- expect(Figly::Settings.some_key).to eq(234)
14
- end
9
+ it 'should correctly access and integer on the top level' do
10
+ expect(Figly::Settings.some_key).to eq(234)
11
+ end
15
12
 
16
- it 'should correctly access an array' do
17
- expect(Figly::Settings.hello).to eq([1,2,3])
18
- end
13
+ it 'should correctly access an array' do
14
+ expect(Figly::Settings.hello).to eq([1,2,3])
15
+ end
19
16
 
20
- it 'should correclty access a hash' do
21
- expect(Figly::Settings.nest1).to eq({'nest2' => {'nest3' => 'Yay'} } )
22
- end
17
+ it 'should correclty access a hash' do
18
+ expect(Figly::Settings.nest1).to eq({'nest2' => {'nest3' => 'Yay'} } )
19
+ end
23
20
 
24
- it 'should correctly access a value nested in a hash' do
25
- expect(Figly::Settings.nest1.nest2.nest3).to eq('Yay')
26
- end
21
+ it 'should correctly access a value nested in a hash' do
22
+ expect(Figly::Settings.nest1.nest2.nest3).to eq('Yay')
23
+ end
24
+
25
+ it 'should correctly access a nestd hash within an array' do
26
+ expect(Figly::Settings.ary.first.nest1.nest2).to eq('Woot')
27
+ end
27
28
 
28
- it 'should correctly access a nestd hash within an array' do
29
- expect(Figly::Settings.ary.first.nest1.nest2).to eq('Woot')
29
+ it 'should return nil when accessing a key that doesnt exist' do
30
+ expect(Figly::Settings.blah).to eq(nil)
31
+ end
30
32
  end
31
33
 
32
- it 'should return nil when accessing a key that doesnt exist' do
33
- expect(Figly::Settings.blah).to eq(nil)
34
+ context 'TOML' do
35
+ before do
36
+ Figly.setup(config_file 'toml')
37
+ end
38
+ it 'should parse and work for TOML' do
39
+ expect(Figly::Settings.a.b).to eq({"c"=>{"d"=>"test"}})
40
+ end
34
41
  end
35
42
 
43
+ context 'JSON' do
44
+ before do
45
+ Figly.setup(config_file 'json')
46
+ end
47
+ it 'should parse and work with JSON' do
48
+ expect(Figly::Settings.userId).to eq(1)
49
+ end
50
+ end
36
51
  end
37
-
@@ -0,0 +1,6 @@
1
+ {
2
+ "userId": 1,
3
+ "id": 1,
4
+ "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
5
+ "body": "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto"
6
+ }
@@ -0,0 +1,43 @@
1
+ # Comment
2
+
3
+ # Booleans
4
+ true = true
5
+ false = false
6
+
7
+ [strings]
8
+ # String
9
+ string = "string\n\t\"string"
10
+ empty = ""
11
+
12
+ [ints]
13
+ simple = 42
14
+ negative = -42
15
+
16
+ [floats]
17
+ pi = 3.14159
18
+ negative = -10.0
19
+
20
+ [datetimes]
21
+ # DateTime
22
+ simple = 1979-05-27T07:32:00Z
23
+
24
+ # Keygroups
25
+ [a.b.c]
26
+ d = "test"
27
+
28
+ [e]
29
+ f = "test"
30
+
31
+ # Post line comment
32
+ [comments]
33
+ on = "a line" # with markup
34
+
35
+ # Multi-line arrays
36
+ [arrays]
37
+ # Simple array
38
+ simple = [1, 2, 3]
39
+
40
+ # Nested array
41
+ nested = [[1, 2], [3]]
42
+
43
+ uneven = [1, 2, 3, 4, 5 ]
@@ -1,11 +1,10 @@
1
1
  module TestEnv
2
- def config_file
3
- File.join(root, 'spec/support/config.yml')
2
+ def config_file(ext = 'yml')
3
+ File.join(root, "spec/support/config.#{ext}")
4
4
  end
5
-
5
+
6
6
  def root
7
7
  support = File.dirname __dir__
8
8
  File.expand_path(File.join(support, ".."))
9
9
  end
10
-
11
10
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Canty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: toml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +102,8 @@ files:
88
102
  - lib/figly/version.rb
89
103
  - spec/figly_spec.rb
90
104
  - spec/spec_helper.rb
105
+ - spec/support/config.json
106
+ - spec/support/config.toml
91
107
  - spec/support/config.yml
92
108
  - spec/support/test_env.rb
93
109
  homepage: ''
@@ -105,17 +121,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
121
  version: '0'
106
122
  required_rubygems_version: !ruby/object:Gem::Requirement
107
123
  requirements:
108
- - - ">"
124
+ - - ">="
109
125
  - !ruby/object:Gem::Version
110
- version: 1.3.1
126
+ version: '0'
111
127
  requirements: []
112
128
  rubyforge_project:
113
- rubygems_version: 2.2.2
129
+ rubygems_version: 2.4.8
114
130
  signing_key:
115
131
  specification_version: 4
116
- summary: A tiny gem that allows you to access config settings from YAML
132
+ summary: A tiny gem that allows you to access config settings from YAML, TOML, or
133
+ JSON
117
134
  test_files:
118
135
  - spec/figly_spec.rb
119
136
  - spec/spec_helper.rb
137
+ - spec/support/config.json
138
+ - spec/support/config.toml
120
139
  - spec/support/config.yml
121
140
  - spec/support/test_env.rb