ure 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/ure/version.rb +1 -1
- data/lib/ure.rb +6 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e305b2b62fb6e0eaafd86a42f25ff8169148fcd
|
4
|
+
data.tar.gz: 47343ec4a7598eedc31b04be9d5d08df753c25c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e48315ac3bb2d73e4897c33458acf4c579d02c901a8bce0afc6e86a82fd774b9a7e20301cb0077a69a89fa115975f209e999b2c2c8161e685df6866b682013
|
7
|
+
data.tar.gz: 7ba18a3abe315b0aaabea54cc11d98eb69cd0b2f5002f0a7b30c37e9188c6ded11dc49d34904310cfbfca843078fa053446cae45a37953d6596afa2ba4496404
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ scooby_van = Car.new
|
|
14
14
|
Even worse, what if we include one argument and forget the other?
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
|
17
|
+
mystery_machine = Car.new(:mural)
|
18
18
|
=> #<struct Car paint=:mural, year=nil>
|
19
19
|
```
|
20
20
|
Fixing it with Struct's built-in accessors after the fact isn't great, either. What we want is a Struct that has required arguments, and then throws a useful error if we give it the wrong thing.
|
@@ -37,7 +37,7 @@ But that's not all.
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
mystery_machine = Car.new
|
40
|
-
|
40
|
+
ArgumentError: missing keyword: paint
|
41
41
|
```
|
42
42
|
|
43
43
|
We get a useful error message, instead of a data object populated with `nil`'s.
|
@@ -78,7 +78,7 @@ Ure's current public methods are:
|
|
78
78
|
|
79
79
|
`#[]` - Because Ure doesn't care about indexing, this allows users to treat instances of Ure as a hash.
|
80
80
|
|
81
|
-
`#each(&block) - Converts the fields into a hash and calls each on them.
|
81
|
+
`#each(&block)` - Converts the fields into a hash and calls each on them.
|
82
82
|
|
83
83
|
`#to_s` - Returns a string describing the object and its fields.
|
84
84
|
|
data/lib/ure/version.rb
CHANGED
data/lib/ure.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "ure/version"
|
2
2
|
class Ure < BasicObject
|
3
|
+
include ::Enumerable
|
3
4
|
def self.members
|
4
5
|
@members
|
5
6
|
end
|
@@ -23,10 +24,10 @@ class Ure < BasicObject
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def initialize(fields = {})
|
26
|
-
fail "'fields' must be a 'Hash'" unless fields.is_a?(::Hash)
|
27
|
+
::Kernel.fail ::ArgumentError, "'fields' must be a 'Hash'" unless fields.is_a?(::Hash)
|
27
28
|
|
28
29
|
members.each do |member|
|
29
|
-
fail ArgumentError, "missing keyword: #{member}" unless fields.include?(member)
|
30
|
+
::Kernel.fail ::ArgumentError, "missing keyword: #{member}" unless fields.include?(member)
|
30
31
|
instance_eval <<-END_RUBY
|
31
32
|
def #{member}
|
32
33
|
i = members.index(#{member.inspect})
|
@@ -35,9 +36,8 @@ class Ure < BasicObject
|
|
35
36
|
END_RUBY
|
36
37
|
end
|
37
38
|
|
38
|
-
unless (extra = fields.keys - members).empty?
|
39
|
-
fail ArgumentError,
|
40
|
-
"unknown keyword#{'s' if extra.size > 1}: #{extra.join(', ')}"
|
39
|
+
unless (extra = fields.keys - members).empty?
|
40
|
+
::Kernel.fail ::ArgumentError, "unknown keyword#{'s' if extra.size > 1}: #{extra.join(', ')}"
|
41
41
|
end
|
42
42
|
|
43
43
|
@values = fields
|
@@ -75,11 +75,6 @@ class Ure < BasicObject
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def values_at(name, *args)
|
78
|
-
|
79
|
-
list << fields[name]
|
80
|
-
args.each do |arg|
|
81
|
-
list << fields[arg]
|
82
|
-
end
|
83
|
-
list
|
78
|
+
[fields[name]] + args.map { |arg| fields[arg] }
|
84
79
|
end
|
85
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clayton Flesher
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|