key_path 1.0.1 → 1.1.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: 7b3b105137df50dc9ec27395c52fc2416ad3c275
4
- data.tar.gz: 07009e35a342fa252077d2e230fa9b7a8556a388
3
+ metadata.gz: 97bec64129322472e98df7f7eae193c2270f600d
4
+ data.tar.gz: 1ec83e17387537141a19fcdcf22d1b7570c2c0d3
5
5
  SHA512:
6
- metadata.gz: 8fc198e9bc7a21908039c10342656edc0bd9fa97de3732a1d2fadb1eb06f9e5a089b3899d80e76686064641d61864925b5a0584c8c75536229943cddf83cf003
7
- data.tar.gz: db56e6b5359f71521d6fd43439a5b009ea9573ea8353f7331450d2178c5313fb4ed3f2df5a74e39193ee0488c70c6608dde81c27505f159dbefe0d51800fb39b
6
+ metadata.gz: e518c330f3fbe00f85ae1cd67d3bac455d85d4002028676107ff502a5b649e85ddc0255384d8c3108cf037af0e7eb44239cd3b1b144c8773b01db2932ddae25b
7
+ data.tar.gz: 7375c073dda8be3321ac281e6e3c2093da18fe443652f59c93132d49e292a88ae486d86208b57c37cd34c6c422869eba63fbc2dd2cd50ef244af724b94db9a6a
data/.travis.yml CHANGED
@@ -1,8 +1,18 @@
1
+ # Send builds to container-based infrastructure
2
+ # http://docs.travis-ci.com/user/workers/container-based-infrastructure/
3
+ sudo: false
1
4
  language: ruby
5
+ cache:
6
+ - bundler
2
7
  rvm:
3
- - 2.0.0
4
- - 2.1.5
5
- - 2.2.0
8
+ - 2.0
9
+ - 2.1
10
+ - 2.2
11
+ - ruby-head
12
+ matrix:
13
+ fast_finish: true
14
+ allow_failures:
15
+ - rvm: ruby-head
6
16
  addons:
7
17
  code_climate:
8
18
  repo_token: 5e894e29c661b239fb363f409ae1043ae689e05b3169f7eaff50be66cc6b4479
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.1.0
4
+
5
+ * (5a95e95) Removes the usage of `eval`. (@PikachuEXE)
6
+ * (625e295) Switches to Travis container infrastructure. (@PikachuEXE)
7
+ * Switches to looser Ruby declarations to improve the coverage.
8
+ * Adds tests against Ruby HEAD (but can fail).
9
+
10
+ ## 1.0.1
11
+
12
+ * (e618da5) Adds a test case for strings with capital letters. (@samuel-hcl)
13
+ * (5601a9f) Fixes an exception when setting a string with capital letters. (@samuel-hcl)
14
+ * (386a925) Updates the README to mention the gem correctly.
15
+ * (64f3649) Improves the installation instructions.
16
+ * (fdcf7d5) Adds CodeClimate for quality and coverage testing.
17
+ * (968b30f) Tests against Ruby 2.1.5, 2.2.0.
18
+ * (47a2663) Fixes Rubocop offenses.
19
+
20
+ ## 1.0.0
21
+
22
+ * (460ff50) Initial release; implements the basic functionality for handling
23
+ "key paths" in Array and Hash objects.
@@ -23,29 +23,32 @@ module Enumerable
23
23
  # handle both string and KeyPath::Path forms
24
24
  keypath = keypath.to_keypath if keypath.is_a?(String)
25
25
 
26
- # create a collection at the keypath
27
- collection = keypath.to_collection
28
-
29
- # set the value in the collection
30
- depth = ''
31
- keypath.to_a.each do |e|
32
- # walk down set and make up the right place to assign
33
- if e.is_number?
34
- key = "#{e}"
35
- else
36
- key = ":#{e}"
37
- end
38
- depth << "[#{key}]"
26
+ keypath_parts = keypath.to_a
27
+ # Return self if path empty
28
+ return self if keypath_parts.empty?
29
+
30
+ key = keypath_parts.shift
31
+ # Just assign value to self when it's a direct path
32
+ # Remember, this is after calling keypath_parts#shift
33
+ if keypath_parts.length == 0
34
+ key = key.is_number? ? Integer(key) : key.to_sym
35
+
36
+ self[key] = value
37
+ return self
39
38
  end
40
39
 
41
- # assign it
42
- if value.is_a? String
43
- eval "collection#{depth} = '#{value}'"
40
+ # keypath_parts.length > 0
41
+ # Remember, this is after calling keypath_parts#shift
42
+ collection = if key.is_number?
43
+ Array.new
44
44
  else
45
- eval "collection#{depth} = #{value}"
45
+ Hash.new
46
46
  end
47
47
 
48
+ # Remember, this is after calling keypath_parts#shift
49
+ collection.set_keypath(keypath_parts.join('.'), value)
50
+
48
51
  # merge the new collection into self
49
- self.deep_merge!(collection)
52
+ self[key] = collection
50
53
  end
51
54
  end
data/lib/key_path/path.rb CHANGED
@@ -24,31 +24,6 @@ module KeyPath
24
24
  @path.split('.')
25
25
  end
26
26
 
27
- def to_collection
28
- collection = {}
29
- s = to_a
30
- depth = ''
31
-
32
- s.each do |e|
33
- # assemble the key
34
- if e.is_number?
35
- key = "#{e}"
36
- else
37
- key = ":#{e}"
38
- end
39
- depth << "[#{key}]"
40
-
41
- # figure out the correct type to push
42
- type = {}
43
- type = [] if e.is_plural?
44
-
45
- # evaluate this stage
46
- eval "collection#{depth} = #{type}"
47
- end
48
-
49
- collection
50
- end
51
-
52
27
  def inspect
53
28
  "#<#{self.class.name}:#{object_id} path=#{@path}>"
54
29
  end
@@ -1,4 +1,4 @@
1
1
  # Version declaration.
2
2
  module KeyPath
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
  end
data/spec/path_spec.rb CHANGED
@@ -37,30 +37,3 @@ describe 'KeyPath::Path main methods' do
37
37
  path.parent.must_be_nil
38
38
  end
39
39
  end
40
-
41
- describe 'KeyPath::Path collections generation' do
42
- it 'returns an empty hash with an empty path' do
43
- path = KeyPath::Path.new('')
44
- path.to_collection.must_equal({})
45
- end
46
-
47
- it 'returns a nested hash for a single path unit' do
48
- path = KeyPath::Path.new('item')
49
- path.to_collection.must_equal(item: {})
50
- end
51
-
52
- it 'returns a nested array when the key is plural' do
53
- path = KeyPath::Path.new('items')
54
- path.to_collection.must_equal(items: [])
55
- end
56
-
57
- it 'returns a double nested array with a two set keypath' do
58
- path = KeyPath::Path.new('item.id')
59
- path.to_collection.must_equal(item: { id: {} })
60
- end
61
-
62
- it 'returns a nested array with an item' do
63
- path = KeyPath::Path.new('items.0.id')
64
- path.to_collection.must_equal(items: [{ id: {} }])
65
- end
66
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Charlton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -77,6 +77,7 @@ files:
77
77
  - ".gitignore"
78
78
  - ".ruby-version"
79
79
  - ".travis.yml"
80
+ - CHANGELOG.md
80
81
  - Gemfile
81
82
  - LICENSE
82
83
  - README.md