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 +4 -4
- data/figly.gemspec +2 -1
- data/lib/figly.rb +19 -5
- data/lib/figly/settings.rb +3 -7
- data/lib/figly/version.rb +1 -1
- data/spec/figly_spec.rb +38 -24
- data/spec/support/config.json +6 -0
- data/spec/support/config.toml +43 -0
- data/spec/support/test_env.rb +3 -4
- metadata +25 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42364b75b7532c60705dbac8b6ef845d5c050fd1
|
4
|
+
data.tar.gz: 967175d1098a36cb2667ef092b3c5e9af0f681cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55611aa6fd7c901dae7cb0d521840b7587f2273f1f14877cb225737a07d40a09cf7cc4f28a077182c18c41ba85f4100cf172cce29bfb543c9661b7ba42a82254
|
7
|
+
data.tar.gz: 40a0f3233a2544f8b95a3cc5a22560ddc96c46ce85c0609b021de7f3aa48d69eb3b0dffc43292aa5e067f1ae98420c0e9863aa9e80ba525699b00e58933109c0
|
data/figly.gemspec
CHANGED
@@ -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"
|
data/lib/figly.rb
CHANGED
@@ -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
|
-
|
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.
|
11
|
-
@@
|
24
|
+
def self.data
|
25
|
+
@@data
|
12
26
|
end
|
13
27
|
end
|
data/lib/figly/settings.rb
CHANGED
@@ -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
|
-
|
21
|
-
|
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
|
data/lib/figly/version.rb
CHANGED
data/spec/figly_spec.rb
CHANGED
@@ -1,37 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Figly do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context 'YAML' do
|
5
|
+
before do
|
6
|
+
Figly.setup(config_file)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
13
|
+
it 'should correctly access an array' do
|
14
|
+
expect(Figly::Settings.hello).to eq([1,2,3])
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
it 'should correclty access a hash' do
|
18
|
+
expect(Figly::Settings.nest1).to eq({'nest2' => {'nest3' => 'Yay'} } )
|
19
|
+
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
33
|
-
|
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 ]
|
data/spec/support/test_env.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module TestEnv
|
2
|
-
def config_file
|
3
|
-
File.join(root,
|
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.
|
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:
|
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:
|
126
|
+
version: '0'
|
111
127
|
requirements: []
|
112
128
|
rubyforge_project:
|
113
|
-
rubygems_version: 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
|