dot_hash 0.5.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96f2a20d001035964bad9b1410aed024647538eb
4
- data.tar.gz: ef40f1c6b2c5d64a555754b94723b23a847063c4
3
+ metadata.gz: edb87b60438f87476c0a33567b0b23270e6d76a4
4
+ data.tar.gz: 84051d724b4f4e1d207fd66fbcfed2266a923f81
5
5
  SHA512:
6
- metadata.gz: 6e7d0dac7042dd443cbcd381079bc29c6c7bb34a78a8c7d51f7fc137642b4db30e106110ed7c490aa500798f58ca26545a7cc882cef746e8d0909c48d6c8c27f
7
- data.tar.gz: db1a85782e03701a13725d277ec8995e33278be9d93d784d61e6a650a1f5cb953481e249f57b1a846cdd9fd10e85e4af031cab5eab95daf4e6781137e43f964c
6
+ metadata.gz: d615ed0055a00c5f7696a10e67902f4802235ee770438ebf284b6cc232db6e3ab3800f402ee372ea944d9e5e67a1c3d4e3656c58c5edca61ab112357a84c4f65
7
+ data.tar.gz: c754aad3c0ba2d9d24335b260b327692f466f2e9ff9e7960dcd2f09acf8de413346f593372a86cf0387eebcbd1288a5de69548197ced1984041430ab20fea796
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.3.0
6
+ - 2.4.0
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # DotHash
3
2
  [![Code Climate](https://codeclimate.com/github/3den/dot_hash.png)](https://codeclimate.com/github/3den/dot_hash) [![Build Status](https://travis-ci.org/3den/dot_hash.png?branch=master)](https://travis-ci.org/3den/dot_hash)
4
3
 
@@ -29,8 +28,24 @@ properties.size.height # returns 100, it is the same as some_hash[:size][:height
29
28
  properties.color # returns "red", it works with Strings and Symbol keys
30
29
  properties[:color] # returns "red", can be used like a hash with string keys
31
30
  properties["color"] # returns "red", can be used like a hash with symbol keys
31
+
32
+ # App Settings
33
+ class Settings < DotHash::Settings
34
+ load 'path/to/some/settings.yaml', 'path/to/settings-directory/', {something: 'Some Value'}
35
+ end
36
+
37
+ # Use the settings as a Singleton
38
+ Settings.something
39
+ Settings.other.stuff.from_yml_settings
40
+
41
+ # Create a settings instance from some YML
42
+ swagger = Settings.new Rails.root.join('config', 'my-swagger.yml')
43
+
44
+ swagger.info.title # returns the title from swagger doc
32
45
  ```
33
46
 
47
+ Check the tests for more details.
48
+
34
49
  ## Contributing
35
50
 
36
51
  1. Fork it
@@ -15,8 +15,8 @@ module DotHash
15
15
  end
16
16
  end
17
17
 
18
- def respond_to_missing?(key, *)
19
- has_key?(key) or super
18
+ def respond_to_missing?(key, *args)
19
+ has_key?(key) or super(key, *args)
20
20
  end
21
21
 
22
22
  def to_s
@@ -1,32 +1,22 @@
1
1
  module DotHash
2
- class Settings
3
- attr_reader :configs
4
-
5
- def initialize(configs, wrapper=Properties)
6
- @configs = wrapper.new(configs)
7
- end
8
-
9
- def method_missing(key, *args, &block)
10
- configs.send(key, *args, &block)
11
- end
12
-
13
- def respond_to?(key)
14
- configs.respond_to?(key)
2
+ class Settings < Properties
3
+ def initialize(*args)
4
+ super Loader.new(*args).load
15
5
  end
16
6
 
17
7
  class << self
18
8
  attr_reader :instance
19
9
 
20
- def method_missing(key, *args, &block)
21
- instance.public_send key, *args, &block
10
+ def method_missing(*args, &block)
11
+ instance.public_send(*args, &block)
22
12
  end
23
13
 
24
- def respond_to?(key)
25
- super(key) || instance.respond_to?(key)
14
+ def respond_to_missing?(*args)
15
+ instance.respond_to?(*args)
26
16
  end
27
17
 
28
18
  def load(*args)
29
- @instance = new Loader.new(*args).load
19
+ @instance = new(*args)
30
20
  end
31
21
 
32
22
  def namespace(namespace)
@@ -1,3 +1,3 @@
1
1
  module DotHash
2
- VERSION = "0.5.9"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -6,12 +6,11 @@ end
6
6
 
7
7
  describe CustomSettings do
8
8
  it "loads the given settings" do
9
- CustomSettings.attributes.power.must_equal 10
10
- CustomSettings.attributes.skills.must_equal ["fireball", "frost"]
9
+ assert_equal CustomSettings.attributes.power, 10
10
+ assert_equal CustomSettings.attributes.skills, ["fireball", "frost"]
11
11
  end
12
12
  end
13
13
 
14
-
15
14
  class CustomSettings2 < DotHash::Settings
16
15
  load attributes: {power: 10, name: "Eden", skills: ["fireball", "frost"]}
17
16
  namespace :attributes
@@ -19,7 +18,7 @@ end
19
18
 
20
19
  describe CustomSettings2 do
21
20
  it "loads the settings within the namespace" do
22
- CustomSettings2.power.must_equal 10
23
- CustomSettings2.skills.must_equal ["fireball", "frost"]
21
+ assert_equal CustomSettings2.power, 10
22
+ assert_equal CustomSettings2.skills, ["fireball", "frost"]
24
23
  end
25
24
  end
@@ -15,11 +15,11 @@ describe Hash do
15
15
  end
16
16
 
17
17
  it "gets nested properties" do
18
- properties.info.name.must_equal "eagle"
18
+ assert_equal properties.info.name, "eagle"
19
19
  end
20
20
 
21
21
  it "gets simple properties" do
22
- properties.price.must_equal 10
22
+ assert_equal properties.price, 10
23
23
  end
24
24
  end
25
25
  end
@@ -9,13 +9,13 @@ module DotHash
9
9
  {a: 1, b: {c: 2}},
10
10
  {b: {x: {z: 10}}}
11
11
  )
12
- loader.load.must_equal({a: 1, b: {c: 2, x: {z: 10}}})
12
+ assert_equal loader.load,({a: 1, b: {c: 2, x: {z: 10}}})
13
13
  end
14
14
 
15
15
  it "loads from a file" do
16
16
  loader = Loader.new fixtures_path("configs1.yaml")
17
17
 
18
- loader.load.must_equal({
18
+ assert_equal loader.load,({
19
19
  "default" => {"attr" => {"speed"=>10, "power"=>11}},
20
20
  "rogue" => {"attr" => {"speed"=>20, "power"=>11}}
21
21
  })
@@ -27,7 +27,7 @@ module DotHash
27
27
  fixtures_path("configs2.yaml")
28
28
  )
29
29
 
30
- loader.load.must_equal({
30
+ assert_equal loader.load,({
31
31
  "default"=>{"attr"=>{"speed"=>10, "power"=>11}},
32
32
  "rogue"=>{"attr"=>{"speed"=>25, "power"=>11}}
33
33
  })
@@ -36,13 +36,13 @@ module DotHash
36
36
  it "does not load files without the yaml extension" do
37
37
  loader = Loader.new fixtures_path("config.yaml.example")
38
38
 
39
- loader.load.must_equal({})
39
+ assert_equal loader.load,({})
40
40
  end
41
41
 
42
42
  it "loads from a directory" do
43
43
  loader = Loader.new fixtures_path
44
44
 
45
- loader.load.must_equal({
45
+ assert_equal loader.load,({
46
46
  "default"=>{"attr"=>{"speed"=>10, "power"=>11}},
47
47
  "rogue"=>{"attr"=>{"speed"=>25, "power"=>11}},
48
48
  "hero"=>{"name"=>"Eden", "power"=>100, "location"=>TESTS_PATH}
@@ -52,7 +52,7 @@ module DotHash
52
52
  it "loads ERB files" do
53
53
  loader = Loader.new fixtures_path("configs3.yaml.erb")
54
54
 
55
- loader.load.must_equal({
55
+ assert_equal loader.load,({
56
56
  "hero"=>{"name"=>"Eden", "power"=>100, "location"=>TESTS_PATH}
57
57
  })
58
58
  end
@@ -11,7 +11,7 @@ module DotHash
11
11
  end
12
12
 
13
13
  it "gets a hash property using the dot notation" do
14
- properties.speed.must_equal "15"
14
+ assert_equal properties.speed, "15"
15
15
  end
16
16
 
17
17
  it "raises an error if the method is not on the hash" do
@@ -21,17 +21,15 @@ module DotHash
21
21
  end
22
22
 
23
23
  it "gets a property from a stringed key" do
24
- properties.power.must_equal 100
24
+ assert_equal properties.power, 100
25
25
  end
26
26
 
27
27
  it "gets all values from a given property" do
28
- properties.values.must_equal ["15", 100]
28
+ assert_equal properties.values, ["15", 100]
29
29
  end
30
30
 
31
31
  it "responds to a block method" do
32
- properties.map do |key, value|
33
- [key, value]
34
- end.must_equal [[:speed, "15"], ["power", 100]]
32
+ assert_equal properties.map { |k, v| [k, v] }, [[:speed, "15"], ["power", 100]]
35
33
  end
36
34
  end
37
35
 
@@ -47,12 +45,12 @@ module DotHash
47
45
  end
48
46
 
49
47
  it "gets chained properties" do
50
- properties.user.info.name.must_equal "dude"
51
- properties.user.info.is_admin.must_equal false
48
+ assert_equal properties.user.info.name, "dude"
49
+ assert_equal properties.user.info.is_admin, false
52
50
  end
53
51
 
54
52
  it 'preserves nil-value nodes' do
55
- properties.user.info.favorite_thing.must_equal nil
53
+ assert_nil properties.user.info.favorite_thing
56
54
  end
57
55
  end
58
56
 
@@ -62,15 +60,15 @@ module DotHash
62
60
  end
63
61
 
64
62
  it "accesses properties like a symbol hash" do
65
- properties[:user][:name].must_equal "dude"
63
+ assert_equal properties[:user][:name], "dude"
66
64
  end
67
65
 
68
66
  it "accesses properties like a string hash" do
69
- properties["user"]["name"].must_equal "dude"
67
+ assert_equal properties["user"]["name"], "dude"
70
68
  end
71
69
 
72
70
  it 'returns nil when value not present' do
73
- properties['missing'].must_equal nil
71
+ assert_nil properties['missing']
74
72
  end
75
73
  end
76
74
  end
@@ -81,7 +79,7 @@ module DotHash
81
79
  end
82
80
 
83
81
  it "returns a hash" do
84
- properties.to_hash.must_equal user: {name: "dude"}
82
+ assert_equal properties.to_hash, user: {name: "dude"}
85
83
  end
86
84
  end
87
85
 
@@ -91,7 +89,7 @@ module DotHash
91
89
  end
92
90
 
93
91
  it "returns a hash" do
94
- properties.to_json.must_equal '{"user":{"name":"dude"}}'
92
+ assert_equal properties.to_json, '{"user":{"name":"dude"}}'
95
93
  end
96
94
  end
97
95
 
@@ -104,7 +102,7 @@ module DotHash
104
102
  end
105
103
 
106
104
  it "returns the hash as a string" do
107
- properties.to_s.must_equal hash.to_s
105
+ assert_equal properties.to_s, hash.to_s
108
106
  end
109
107
  end
110
108
 
@@ -144,16 +142,16 @@ module DotHash
144
142
  end
145
143
 
146
144
  it 'has a capturable method for a simple property' do
147
- @properties.method(:speed).call.must_equal "100"
145
+ assert_equal @properties.method(:speed).call, "100"
148
146
  end
149
147
 
150
148
  it 'has a capturable method for a nested property' do
151
- @properties.info.method(:name).call.must_equal "Eden"
152
- @properties.method(:info).call.name.must_equal "Eden"
149
+ assert_equal @properties.info.method(:name).call, "Eden"
150
+ assert_equal @properties.method(:info).call.name, "Eden"
153
151
  end
154
152
 
155
153
  it 'has a capturable method for a string property' do
156
- @properties.method(:color).call.must_equal "#00FFBB"
154
+ assert_equal @properties.method(:color).call, "#00FFBB"
157
155
  end
158
156
 
159
157
  it 'does not have a capturable method for a missing property' do
@@ -11,13 +11,13 @@ module DotHash
11
11
  end
12
12
 
13
13
  it "gets hash properties" do
14
- settings.site.must_equal "skyo.com"
15
- settings[:site].must_equal "skyo.com"
14
+ assert_equal settings.site, "skyo.com"
15
+ assert_equal settings[:site], "skyo.com"
16
16
  end
17
17
 
18
18
  it "gets a nested hash property" do
19
- settings.facebook.api.must_equal "123"
20
- settings['facebook']['api'].must_equal "123"
19
+ assert_equal settings.facebook.api, "123"
20
+ assert_equal settings['facebook']['api'], "123"
21
21
  end
22
22
  end
23
23
 
@@ -29,6 +29,12 @@ module DotHash
29
29
 
30
30
  it "responds to a property on the configs" do
31
31
  settings.must_respond_to :site
32
+ settings.must_respond_to :hash
33
+ settings.must_respond_to :to_s
34
+ end
35
+
36
+ it "does not responds to crasy stuff" do
37
+ settings.wont_respond_to :foobar
32
38
  end
33
39
  end
34
40
 
@@ -50,8 +56,8 @@ module DotHash
50
56
  end
51
57
 
52
58
  it "gets hash properties" do
53
- Settings.site.must_equal "skyo.com"
54
- Settings['site'].must_equal "skyo.com"
59
+ assert_equal Settings.site, "skyo.com"
60
+ assert_equal Settings['site'], "skyo.com"
55
61
  end
56
62
  end
57
63
 
@@ -73,23 +79,23 @@ module DotHash
73
79
  end
74
80
 
75
81
  it "adds new properties to the previous hash" do
76
- Settings.b.x.z.must_equal 10
82
+ assert_equal Settings.b.x.z, 10
77
83
  end
78
84
 
79
85
  it "keeps non-changed properties untouched" do
80
- Settings.a.must_equal 1
86
+ assert_equal Settings.a, 1
81
87
  end
82
88
 
83
89
  it "merges nested hashes correctly" do
84
- Settings.b.c.must_equal 2
90
+ assert_equal Settings.b.c, 2
85
91
  end
86
92
  end
87
93
 
88
94
  describe "loading from files" do
89
95
  it "loads from a file" do
90
96
  Settings.load fixtures_path("configs1.yaml")
91
- Settings.rogue.attr.speed.must_equal 20
92
- Settings.rogue.attr.power.must_equal 11
97
+ assert_equal Settings.rogue.attr.speed, 20
98
+ assert_equal Settings.rogue.attr.power, 11
93
99
  end
94
100
 
95
101
  it "loads from two files" do
@@ -98,8 +104,8 @@ module DotHash
98
104
  fixtures_path("configs2.yaml")
99
105
  )
100
106
 
101
- Settings.rogue.attr.speed.must_equal 25
102
- Settings.rogue.attr.power.must_equal 11
107
+ assert_equal Settings.rogue.attr.speed, 25
108
+ assert_equal Settings.rogue.attr.power, 11
103
109
  end
104
110
 
105
111
  it "does not load files without the yaml extension" do
@@ -110,8 +116,8 @@ module DotHash
110
116
 
111
117
  it "loads from a directory" do
112
118
  Settings.load fixtures_path
113
- Settings.rogue.attr.speed.must_equal 25
114
- Settings.rogue.attr.power.must_equal 11
119
+ assert_equal Settings.rogue.attr.speed, 25
120
+ assert_equal Settings.rogue.attr.power, 11
115
121
  end
116
122
  end
117
123
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Eden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Access hash values using the dot notation
@@ -31,8 +31,8 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - .gitignore
35
- - .travis.yml
34
+ - ".gitignore"
35
+ - ".travis.yml"
36
36
  - Gemfile
37
37
  - LICENSE
38
38
  - README.md
@@ -63,17 +63,17 @@ require_paths:
63
63
  - lib
64
64
  required_ruby_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - '>='
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.1.10
76
+ rubygems_version: 2.6.8
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Converts hash.to_properties so you can access values using properties.some_key