sycamore 0.3.0 → 0.3.1

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: a9ca22a9fa8a7caafbbce1f4a166ff6a43780493
4
- data.tar.gz: ed6fa35d1e3bdef4d41d3642153437755dc0d708
3
+ metadata.gz: 3400b36a441f2a76477f4d0de2e6ffca2daefe49
4
+ data.tar.gz: cf08112b5fbe999cb12e09736a6828912c7cc41a
5
5
  SHA512:
6
- metadata.gz: 55180ebbfd457ba351a0ad933bcf5064e3de0efa9bb032bcc0c8bf4e9493abe108ad2a40d2de82a584beadc57973b92ffb9027aabbb84bd8a6a070de55cab77d
7
- data.tar.gz: ac5e395633685242d42b6b3710441274425266ecaa2246298c6434146b65df1e2993bc5ad9de266f1d9e94dd9c193fa8be12dfe416b079192932cb4efe5f5ac4
6
+ metadata.gz: b4675895dca790b7a8968fba0363ca713d592b1be4454fc23446e26f607f7b5dc75bfca6bd572a35bd477a989df265a19ba692fb2a09dfe078d44c625e509fe3
7
+ data.tar.gz: 5ee07612195732f7c15234c9f8f8555e60ba3cb557de10d44c104c89f7819c15ba41606cebed3783e42d965841ccc25abbaa7e58b0a49a0279b9cecd4f41a899
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
+ /.ruby-version
4
5
  /_yardoc/
5
6
  /coverage/
6
7
  /doc
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
+ bundler_args: --without debug
2
3
  rvm:
3
- - 2.1
4
4
  - 2.2.4
5
- - 2.3.0
6
- - jruby-9.0.4.0
7
- - rbx-2
5
+ - 2.3.1
6
+ - jruby-9.0.5.0
7
+ - rbx
8
8
  cache: bundler
9
9
  before_install:
10
10
  - gem update bundler
@@ -5,6 +5,22 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
5
5
  [Keep a CHANGELOG](http://keepachangelog.com).
6
6
 
7
7
 
8
+ ## 0.3.1 - 2016-05-07
9
+
10
+ ### Added
11
+
12
+ - array-access operator and `fetch` on `Path` for random access
13
+
14
+ ### Changed
15
+
16
+ - Lazy initialization of the internal hash. This improves extensibility, eg. by
17
+ not requiring a `super` call in the constructors of `Tree` subclasses.
18
+
19
+
20
+ [Compare v0.3.0...v0.3.1](https://github.com/marcelotto/sycamore/compare/v0.3.0...v0.3.1)
21
+
22
+
23
+
8
24
  ## 0.3.0 - 2016-04-23
9
25
 
10
26
  ### Added
@@ -32,6 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
32
48
  - `Tree#delete` deleted paths, when they matched a given input path partially,
33
49
  e.g. `Tree[a: 1] >> a: {1 => 2}` deleted successfully.
34
50
 
51
+
35
52
  [Compare v0.2.1...v0.3.0](https://github.com/marcelotto/sycamore/compare/v0.2.1...v0.3.0)
36
53
 
37
54
 
@@ -47,6 +64,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
47
64
 
48
65
  - [#2](https://github.com/marcelotto/sycamore/issues/2): Rubinius support
49
66
 
67
+
50
68
  [Compare v0.2.0...v0.2.1](https://github.com/marcelotto/sycamore/compare/v0.2.0...v0.2.1)
51
69
 
52
70
 
@@ -60,6 +78,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
60
78
  - `Tree#node!` as a more strict variant of `Tree#node`, which raises an error
61
79
  when no node present
62
80
 
81
+
63
82
  [Compare v0.1.0...v0.2.0](https://github.com/marcelotto/sycamore/compare/v0.1.0...v0.2.0)
64
83
 
65
84
 
data/Gemfile CHANGED
@@ -2,9 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :development do
5
+ group :debug do
6
6
  gem 'guard-rspec'
7
- gem 'listen', '< 3.1' # to circumvent the fail for Ruby 2.1 and Rubinius
8
7
  gem 'pry'
9
8
  end
10
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module Sycamore
2
4
 
3
5
  ##
@@ -21,6 +23,7 @@ module Sycamore
21
23
  #
22
24
  class Path
23
25
  include Enumerable
26
+ extend Forwardable
24
27
 
25
28
  attr_reader :node, :parent
26
29
 
@@ -75,6 +78,8 @@ module Sycamore
75
78
  # @group Elements
76
79
  ########################################################################
77
80
 
81
+ def_delegators :to_a, :[], :fetch
82
+
78
83
  ##
79
84
  # Returns a new path based on this path, but with the given nodes extended.
80
85
  #
@@ -65,7 +65,14 @@ module Sycamore
65
65
  # Creates a new empty Tree.
66
66
  #
67
67
  def initialize
68
- @data = Hash.new
68
+ end
69
+
70
+ protected def data
71
+ @data ||= Hash.new
72
+ end
73
+
74
+ protected def clear_data
75
+ @data = nil
69
76
  end
70
77
 
71
78
  ##
@@ -218,7 +225,7 @@ module Sycamore
218
225
  alias << add
219
226
 
220
227
  protected def add_node(node)
221
- @data[node] ||= Nothing
228
+ data[node] ||= Nothing
222
229
 
223
230
  self
224
231
  end
@@ -227,7 +234,7 @@ module Sycamore
227
234
  # @api private
228
235
  #
229
236
  def clear_child_of_node(node)
230
- @data[valid_node! node] = Nothing
237
+ data[valid_node! node] = Nothing
231
238
 
232
239
  self
233
240
  end
@@ -238,8 +245,8 @@ module Sycamore
238
245
  def add_node_with_empty_child(node)
239
246
  valid_node! node
240
247
 
241
- if @data.fetch(node, Nothing).nothing?
242
- @data[node] = new_child(node)
248
+ if data.fetch(node, Nothing).nothing?
249
+ data[node] = new_child(node)
243
250
  end
244
251
 
245
252
  self
@@ -249,7 +256,7 @@ module Sycamore
249
256
  return add_node(node) if Nothing.like?(children)
250
257
 
251
258
  add_node_with_empty_child(node)
252
- @data[node] << children
259
+ data[node] << children
253
260
 
254
261
  self
255
262
  end
@@ -329,7 +336,7 @@ module Sycamore
329
336
  alias >> delete
330
337
 
331
338
  protected def delete_node(node)
332
- @data.delete(node)
339
+ data.delete(node)
333
340
 
334
341
  self
335
342
  end
@@ -491,7 +498,7 @@ module Sycamore
491
498
  # tree.size # => 0
492
499
  #
493
500
  def clear
494
- @data.clear
501
+ data.clear
495
502
 
496
503
  self
497
504
  end
@@ -509,7 +516,7 @@ module Sycamore
509
516
  # tree.to_h # => {foo: :bar}
510
517
  #
511
518
  def compact
512
- @data.each do |node, child| case
519
+ data.each do |node, child| case
513
520
  when child.nothing? then next
514
521
  when child.empty? then clear_child_of_node(node)
515
522
  else child.compact
@@ -535,7 +542,7 @@ module Sycamore
535
542
  # tree[:foo].nodes # => [:bar, :baz]
536
543
  #
537
544
  def nodes
538
- @data.keys
545
+ data.keys
539
546
  end
540
547
 
541
548
  alias keys nodes # Hash compatibility
@@ -605,7 +612,7 @@ module Sycamore
605
612
  def child_of(node)
606
613
  valid_node! node
607
614
 
608
- Nothing.like?(child = @data[node]) ? Absence.at(self, node) : child
615
+ Nothing.like?(child = data[node]) ? Absence.at(self, node) : child
609
616
  end
610
617
 
611
618
  ##
@@ -684,7 +691,7 @@ module Sycamore
684
691
  return fetch_path(node, *default, &block) if node.is_a? Path
685
692
  valid_node! node
686
693
 
687
- child = @data.fetch(node, *default, &block)
694
+ child = data.fetch(node, *default, &block)
688
695
  if child.equal? Nothing
689
696
  child = case
690
697
  when block_given? then yield
@@ -754,7 +761,7 @@ module Sycamore
754
761
  def each_node(&block)
755
762
  return enum_for(__callee__) unless block_given?
756
763
 
757
- @data.each_key(&block)
764
+ data.each_key(&block)
758
765
 
759
766
  self
760
767
  end
@@ -783,7 +790,7 @@ module Sycamore
783
790
  def each_pair(&block)
784
791
  return enum_for(__callee__) unless block_given?
785
792
 
786
- @data.each_pair(&block)
793
+ data.each_pair(&block)
787
794
 
788
795
  self
789
796
  end
@@ -870,7 +877,7 @@ module Sycamore
870
877
  def include_node?(node)
871
878
  return include_path?(node) if node.is_a? Path
872
879
 
873
- @data.include?(node)
880
+ data.include?(node)
874
881
  end
875
882
 
876
883
  alias member? include_node? # Hash compatibility
@@ -954,7 +961,7 @@ module Sycamore
954
961
  # tree["e"].size # => 2
955
962
  #
956
963
  def size
957
- @data.size
964
+ data.size
958
965
  end
959
966
 
960
967
  ##
@@ -971,7 +978,7 @@ module Sycamore
971
978
  #
972
979
  def total_size
973
980
  total = size
974
- @data.each { |_, child| total += child.total_size }
981
+ data.each { |_, child| total += child.total_size }
975
982
  total
976
983
  end
977
984
 
@@ -1001,7 +1008,7 @@ module Sycamore
1001
1008
  # Tree[a: 1].empty? # => false
1002
1009
  #
1003
1010
  def empty?
1004
- @data.empty?
1011
+ data.empty?
1005
1012
  end
1006
1013
 
1007
1014
  alias blank? empty?
@@ -1146,7 +1153,7 @@ module Sycamore
1146
1153
  # @return [Fixnum]
1147
1154
  #
1148
1155
  def hash
1149
- @data.hash ^ self.class.hash
1156
+ data.hash ^ self.class.hash
1150
1157
  end
1151
1158
 
1152
1159
  ##
@@ -1165,7 +1172,7 @@ module Sycamore
1165
1172
  # tree1.eql? tree4 # => false
1166
1173
  #
1167
1174
  def eql?(other)
1168
- (other.instance_of?(self.class) and @data.eql?(other.data)) or
1175
+ (other.instance_of?(self.class) and data.eql?(other.data)) or
1169
1176
  (other.instance_of?(Absence) and other.eql?(self))
1170
1177
  end
1171
1178
 
@@ -1339,7 +1346,7 @@ module Sycamore
1339
1346
  # not the nicest, but fastest way to inject on hashes, as noted here:
1340
1347
  # http://stackoverflow.com/questions/3230863/ruby-rails-inject-on-hashes-good-style
1341
1348
  hash = {}
1342
- @data.each do |node, child|
1349
+ data.each do |node, child|
1343
1350
  hash[node] = child.to_native_object(*args)
1344
1351
  end
1345
1352
 
@@ -1444,7 +1451,7 @@ module Sycamore
1444
1451
  #
1445
1452
  def initialize_clone(other)
1446
1453
  super
1447
- @data = Hash.new
1454
+ clear_data
1448
1455
  add other
1449
1456
  end
1450
1457
 
@@ -1454,7 +1461,7 @@ module Sycamore
1454
1461
  # @see http://ruby-doc.org/core/Object.html#method-i-freeze
1455
1462
  #
1456
1463
  def freeze
1457
- @data.freeze
1464
+ data.freeze
1458
1465
  each { |_, child| child.freeze }
1459
1466
  super
1460
1467
  end
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = '>= 2.1'
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.9'
25
- spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
+ spec.add_development_dependency 'rake', '~> 11.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.4.0'
27
27
  spec.add_development_dependency 'yard', '~> 0.8'
28
28
  spec.add_development_dependency 'yard-doctest'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sycamore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcel Otto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-23 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: '1.11'
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
- version: '1.9'
26
+ version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '11.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '11.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +90,6 @@ files:
90
90
  - ".editorconfig"
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
- - ".ruby-version"
94
93
  - ".travis.yml"
95
94
  - ".yardopts"
96
95
  - AUTHORS
@@ -1 +0,0 @@
1
- 2.3.0