valise 1.1.3 → 1.1.4

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: a283caacd236ce4be21dd9f0e2d3df40948c3bdb
4
- data.tar.gz: 49c285b29cded418465616fc560392a5d05dda71
3
+ metadata.gz: 455879a100dafe54e0baa03a50d495b22bc34e78
4
+ data.tar.gz: 3fb179de644e34d38e4680bd50f730fc824c0cc3
5
5
  SHA512:
6
- metadata.gz: 8a36a7e75ec4ee6e1b83105d3b675b2289a2d4f11a343876a8b84c37cdb9f2aa275fcb71a436fb9f2983e3725bb8e4a76a0fd5a0f90e51e6939ac4147d245781
7
- data.tar.gz: 00b1168bfa5f39af1d09f9b686f7ec0951fff8e3289b93254b0ddf153de17cb854f91cae3a5da1984ac5d813dfecd964803a2dbc648f86f4963b0ef9f31817fd
6
+ metadata.gz: b35098b0c0587b040bb0bbeee1f7e1b2c2f41d9c28e4bf5f7753449a88909a969297f3d7fb887ed1690034f12a9cf557748d3c4af5b88a8ea9f09bde296ba19f
7
+ data.tar.gz: e1acc62569e4318f638ef414753380f88ca4a250db916ca4cdb67138ee2204b5090a4be3ab5195d7b02d0b0f01d08f745d5bcc2b98ab5ae0d2eab9f3d1138d45
@@ -21,6 +21,14 @@ module Valise
21
21
  def serialization
22
22
  set.serialization
23
23
  end
24
+
25
+ def add_serialization_handler(pattern, serializer, options = nil)
26
+ set.add_serialization_handler(pattern, serializer, options)
27
+ end
28
+
29
+ def add_merge_handler(pattern, merger, options = nil)
30
+ set.add_merge_handler(pattern, merger, options)
31
+ end
24
32
  end
25
33
 
26
34
  class PrefixesDecorator < Decorator
@@ -25,11 +25,11 @@ module Valise
25
25
  end
26
26
 
27
27
  def merge_diff
28
- @valise.merge_diff_for(self)
28
+ valise.merge_diff_for(self)
29
29
  end
30
30
 
31
31
  def dump_load
32
- @valise.serialization_for(self)
32
+ valise.serialization_for(self)
33
33
  end
34
34
 
35
35
  def merged(item)
@@ -81,7 +81,7 @@ module Valise
81
81
  end
82
82
 
83
83
  def reget(root)
84
- root.get(@segments)
84
+ root.get(segments)
85
85
  end
86
86
 
87
87
  def item_for(root)
@@ -5,21 +5,19 @@ module Valise
5
5
  class Decorator < Stack
6
6
  def initialize(stack)
7
7
  @stack = stack
8
- @stacks = Hash.new do |h,segments|
9
- h[segments] = @stack.valise.get(segments)
10
- end
8
+ @stacks = {}
11
9
  end
12
10
 
13
- def valise
14
- @stack.valise
11
+ def sub_stack(segments)
12
+ @stacks[segments] ||= @stack.valise.get(segments)
15
13
  end
16
14
 
17
- def merged(item)
18
- item.stack.merged(item)
15
+ def segments
16
+ @stack.segments
19
17
  end
20
18
 
21
- def diffed(item, value)
22
- item.stack.diffed(item, value)
19
+ def valise
20
+ @stack.valise
23
21
  end
24
22
 
25
23
  def rel_path
@@ -14,18 +14,44 @@ module Valise
14
14
  end
15
15
 
16
16
  def reget(root)
17
- decorated = self.new(super)
17
+ decorated = self.class.new(super(root))
18
18
  decorated.extensions = self.extensions
19
19
  decorated
20
20
  end
21
21
 
22
+ def sub_stack(stack, ext)
23
+ SingleExtensionDecorator.new(stack, self, ext)
24
+ end
25
+
22
26
  def decorate_item(item)
23
- dir, file = *item.segments.split
24
27
  @extensions.each do |ext|
25
- ext_stack = @stacks[dir + (file.to_s + ext)]
28
+ ext_stack = sub_stack(item.stack, ext)
26
29
  yield(ext_stack.item_for(item.root))
27
30
  end
28
31
  end
29
32
  end
33
+
34
+ class SingleExtensionDecorator < Decorator
35
+ def initialize(stack, lead_decco, ext)
36
+ super(stack)
37
+ @leader = lead_decco
38
+ @ext = ext
39
+
40
+ dir, file = *(stack.segments.split.map(&:to_s))
41
+ @segments = make_pathname([dir, (file.to_s + ext)])
42
+ end
43
+
44
+ def inspect
45
+ @stack.inspect + @ext
46
+ end
47
+
48
+ def segments
49
+ @segments
50
+ end
51
+
52
+ def reget(root)
53
+ @leader.reget(root)
54
+ end
55
+ end
30
56
  end
31
57
  end
@@ -19,13 +19,39 @@ module Valise
19
19
  decorated
20
20
  end
21
21
 
22
+ def sub_stack(stack, pfx)
23
+ SinglePrefixDecorator.new(stack, self, pfx)
24
+ end
25
+
22
26
  def decorate_item(item)
23
- dir, file = *item.segments.split
24
27
  @prefixes.each do |pfx|
25
- dec_stack = @stacks[dir + (pfx + file.to_s)]
28
+ dec_stack = sub_stack(item.stack, pfx)
26
29
  yield(dec_stack.item_for(item.root))
27
30
  end
28
31
  end
29
32
  end
33
+
34
+ class SinglePrefixDecorator < Decorator
35
+ def initialize(stack, lead_decco, pfx)
36
+ super(stack)
37
+ @leader = lead_decco
38
+ @pfx = pfx
39
+
40
+ dir, file = *(stack.segments.split.map(&:to_s))
41
+ @segments = make_pathname([dir, (pfx + file.to_s)])
42
+ end
43
+
44
+ def inspect
45
+ @stack.inspect + "^#@pfx"
46
+ end
47
+
48
+ def segments
49
+ @segments
50
+ end
51
+
52
+ def reget(root)
53
+ @leader.reget(root)
54
+ end
55
+ end
30
56
  end
31
57
  end
@@ -24,11 +24,11 @@ module Valise
24
24
  register :hash_merge
25
25
 
26
26
  def merge(item)
27
- merge_stack(@stack.not_above(item).reverse)
27
+ merge_stack(@stack.not_above(item))
28
28
  end
29
29
 
30
30
  def merge_stack(stack)
31
- stack.present.inject({}) do |hash, item|
31
+ stack.present.reverse_each.inject({}) do |hash, item|
32
32
  deep_merge(hash, item.load_contents)
33
33
  end
34
34
  end
@@ -129,7 +129,7 @@ module Valise
129
129
  when ::File
130
130
  parts = parts.path
131
131
  else
132
- raise ArgumentError, "path must be String, Array of Strings or File"
132
+ raise ArgumentError, "path must be String, Array of Strings or File, was: #{parts.inspect} (#{parts.class})"
133
133
  end
134
134
  pathname = clean_pathname(Pathname.new(parts))
135
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Judson Lester
@@ -210,7 +210,7 @@ rdoc_options:
210
210
  - --main
211
211
  - doc/README
212
212
  - --title
213
- - valise-1.1.3 RDoc
213
+ - valise-1.1.4 RDoc
214
214
  require_paths:
215
215
  - lib/
216
216
  required_ruby_version: !ruby/object:Gem::Requirement