nrser 0.2.0.pre.0 → 0.2.0.pre.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: b51533291e377070a1f4cac954fc49eee602d178
4
- data.tar.gz: 57c89f078878e050a01dfd8a1b1c00a345de7cb5
3
+ metadata.gz: 942988b83ec5c05fed5f15e87869dd0f20044db8
4
+ data.tar.gz: 57bc680b81ffe4f7650b1200d0aa21a8579be60a
5
5
  SHA512:
6
- metadata.gz: 6305b4adf84631b859377ed9c30d065b617b157299c066a0f8333f9133d979ccf37424cdc16ce3c6cef0219a95e769294cd19148b299f48358bb7934715b7003
7
- data.tar.gz: 5cbf8bb41e319263a4eda303cdf0651080f628a566f723ca185136b198b3089e89b74b22b3b46f815b553ecb0a770eb48b28c09f935148dde7bd0338dc4201e6
6
+ metadata.gz: eec00863e1a07aa333d71a66139773d7f198efcfa137e6aa57607d619431854a2850e54e7ae59c8e1dbbc28f9bd887969f36aef584d703bb0830a345e1540bb9
7
+ data.tar.gz: 3129461e852e4a830e7dcf0dd097c32e017fa4e99541ed76f1bb9670025575a6ec9f3570ad9390a397f6ca733a051b5349d0865a5103656a0bf22be5948e4f7c
@@ -50,7 +50,7 @@ module NRSER
50
50
  # @todo Document return value.
51
51
  #
52
52
  def self.deep_symbolize_keys object, &block
53
- deep_transform_keys( object ) { key.to_sym rescue key }
53
+ deep_transform_keys( object ) { |key| key.to_sym rescue key }
54
54
  end # .deep_symbolize_keys
55
55
 
56
56
 
@@ -31,19 +31,41 @@ module NRSER::Types
31
31
  end
32
32
 
33
33
 
34
- # a combinator may attempt to parse from a string if any of it's types
35
- # can do so
36
- def has_from_s?
37
- @types.any? {|type| type.has_from_s?}
38
- end
39
-
40
-
41
- # a combinator iterates through each of it's types, trying the
42
- # conversion and seeing if the result satisfies the combinator type
43
- # itself. the first such value found is returned.
34
+ # Parse a satisfying value from a {String} or raise a {TypeError}.
35
+ #
36
+ # If this type has it's own `@from_s` that was provided via the `from_s:`
37
+ # keyword at construction, then that and **only** that is **always** used
38
+ # - the type will never try any of the combined types' `#from_s`.
39
+ #
40
+ # It's considered *the* way to parse a string into a value that satisfies
41
+ # the type. If it fails, a {TypeError} will be raised (or any error the
42
+ # `@from_s` proc itself raises before we get to checking it).
43
+ #
44
+ # If the type doesn't have it's own `@from_s`, each of the combined types'
45
+ # `#from_s` will be tried in sequence, and the first value that satisfies
46
+ # the combined type will be returned.
47
+ #
48
+ # This is obviously much less efficient, but provides a nice automatic
49
+ # mechanism for parsing from strings for combined types. If none of the
50
+ # combined types' `#from_s` succeed (or if there are none) a {TypeError}
51
+ # is raised.
52
+ #
53
+ # @param [String] s
54
+ # String to parse.
55
+ #
56
+ # @return [Object]
57
+ # Object that satisfies the type.
58
+ #
59
+ # @raise [TypeError]
60
+ # See write up above.
61
+ #
44
62
  def from_s s
63
+ unless @from_s.nil?
64
+ return check @from_s.call( s )
65
+ end
66
+
45
67
  @types.each { |type|
46
- if type.respond_to? :from_s
68
+ if type.has_from_s?
47
69
  begin
48
70
  return check type.from_s(s)
49
71
  rescue TypeError => e
@@ -57,15 +79,20 @@ module NRSER::Types
57
79
  end
58
80
 
59
81
 
60
- # Overridden to delegate functionality to the combined types:
82
+ # Overridden to delegate functionality to the combined types.
83
+ #
84
+ # A combinator may attempt to parse from a string if:
85
+ #
86
+ # 1. It has it's own `@from_s` provided at construction.
87
+ #
88
+ # 2. Any of it's combined types can parse from a string.
61
89
  #
62
- # A combinator may attempt to parse from a string if any of it's types
63
- # can do so.
90
+ # See {#from_s} for details of how it actually happens.
64
91
  #
65
92
  # @return [Boolean]
66
93
  #
67
94
  def has_from_s?
68
- @types.any? {|type| type.has_from_s?}
95
+ super() || @types.any? { |type| type.has_from_s? }
69
96
  end # has_from_s
70
97
 
71
98
 
@@ -21,7 +21,9 @@ module NRSER::Types
21
21
  end
22
22
 
23
23
  def == other
24
- equal?(other) || @value === other.value
24
+ equal?(other) ||
25
+ ( self.class == other.class &&
26
+ @value == other.value )
25
27
  end
26
28
 
27
29
  # @return [String]
@@ -104,6 +104,7 @@ module NRSER::Types
104
104
  path,
105
105
  where { |path| path.to_pn.absolute? },
106
106
  name: name,
107
+ from_s: ->( s ) { File.expand_path s },
107
108
  **options
108
109
  end
109
110
 
data/lib/nrser/version.rb CHANGED
@@ -18,7 +18,7 @@ module NRSER
18
18
  #
19
19
  # @return [String]
20
20
  #
21
- VERSION = "0.2.0.pre.0"
21
+ VERSION = "0.2.0.pre.1"
22
22
 
23
23
 
24
24
  module Version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre.0
4
+ version: 0.2.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hamster
@@ -431,7 +431,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
431
431
  version: 1.3.1
432
432
  requirements: []
433
433
  rubyforge_project:
434
- rubygems_version: 2.5.2
434
+ rubygems_version: 2.5.2.2
435
435
  signing_key:
436
436
  specification_version: 4
437
437
  summary: basic ruby utils i use in a lot of stuff.