object_identifier 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +53 -19
- data/lib/object_identifier/core_ext/big_decimal.rb +7 -4
- data/lib/object_identifier/core_ext/object.rb +20 -7
- data/lib/object_identifier/core_ext/string.rb +3 -1
- data/lib/object_identifier/core_ext/symbol.rb +3 -1
- data/lib/object_identifier/identifier.rb +39 -31
- data/lib/object_identifier/version.rb +1 -1
- data/test/core_ext/big_decimal_test.rb +1 -1
- data/test/core_ext/string_test.rb +1 -1
- data/test/core_ext/symbol_test.rb +1 -1
- data/test/object_identifier_test.rb +20 -20
- data/test/test_helper.rb +1 -2
- metadata +3 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8ddc2ad9b41c164acd506d459485a07fec316df
|
|
4
|
+
data.tar.gz: 1db0b95efe25e89e27dbce11275f7662fccc3b5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab5c8a2a62cba5aebfca5ac676b9b3dc3e4221e7112ecaea1027ae7df57dcb42daf09654927ac6fe80ffe6069052f878c1bef8747336fd467943f92576563add
|
|
7
|
+
data.tar.gz: 21d76f36afa3abe23f84caf8d9c70e5f52b3e640500675b0aa6ad14030e03978ad05a9c99dab7e3351631ac8b37c9303dd71b1e2873d847d7a091824fec3a697
|
data/README.md
CHANGED
|
@@ -2,32 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/object_identifier)
|
|
4
4
|
|
|
5
|
-
Object Identifier allows quick, easy, and uniform identification of an object
|
|
6
|
-
by inspecting its class name and any desirable attributes/methods. This is great
|
|
7
|
-
for logging, notifications or any other purpose.
|
|
5
|
+
Object Identifier allows quick, easy, and uniform identification of an object by inspecting its class name and outputting any desirable attributes/methods. This is great for quickly logging, sending more descriptive notifications, or any other purpose.
|
|
8
6
|
|
|
9
|
-
For example
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
For example:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
some_object.identify(:id, :name)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Which is the same as:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
"#{some_object.class.name}[id:#{some_object.id}, name:'#{some_object.name}']"
|
|
17
|
+
```
|
|
13
18
|
|
|
14
19
|
|
|
15
20
|
## Compatibility
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
* Ruby: MRI 1.9.3+
|
|
23
|
+
* Ruby: MRI 2+
|
|
24
|
+
* Rails: 3+
|
|
18
25
|
|
|
19
|
-
* Ruby: MRI 1.9.3
|
|
20
|
-
* Ruby: MRI 2.0.0
|
|
21
|
-
* Ruby: MRI 2.1.0
|
|
22
|
-
* Rails: 3.2
|
|
23
|
-
* Rails: 4.0.1
|
|
24
26
|
|
|
25
27
|
## Installation
|
|
26
28
|
|
|
27
29
|
Add this line to your application's Gemfile:
|
|
28
30
|
|
|
29
31
|
```ruby
|
|
30
|
-
gem
|
|
32
|
+
gem 'object_identifier'
|
|
31
33
|
```
|
|
32
34
|
|
|
33
35
|
And then execute:
|
|
@@ -36,9 +38,10 @@ And then execute:
|
|
|
36
38
|
bundle
|
|
37
39
|
```
|
|
38
40
|
|
|
41
|
+
|
|
39
42
|
## Usage
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
### Defaults
|
|
42
45
|
|
|
43
46
|
Outputs the `id` attribute by default, if possible and if no other attributes
|
|
44
47
|
are given:
|
|
@@ -53,7 +56,7 @@ Also works with methods:
|
|
|
53
56
|
some_object.identify(:get_rating) # => Movie[get_rating:"7/10"]
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
### Unknown Attributes/Methods
|
|
57
60
|
|
|
58
61
|
If the object doesn't respond to a specified attribute/method it is simply
|
|
59
62
|
ignored:
|
|
@@ -62,7 +65,7 @@ ignored:
|
|
|
62
65
|
some_object.identify(:gobble_gobble, :id) # => Movie[id:1]
|
|
63
66
|
```
|
|
64
67
|
|
|
65
|
-
|
|
68
|
+
### Collections
|
|
66
69
|
|
|
67
70
|
Works great with collections:
|
|
68
71
|
|
|
@@ -78,7 +81,7 @@ Also allows limiting of results:
|
|
|
78
81
|
# => Movie[id:1, name:"Pi"], ... (1 more)
|
|
79
82
|
```
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
### Overriding the Class Name
|
|
82
85
|
|
|
83
86
|
```ruby
|
|
84
87
|
some_object.identify(klass: "MyMovie") # => MyMovie[id:1]
|
|
@@ -86,13 +89,44 @@ some_object.identify(klass: nil) # => [id:1]
|
|
|
86
89
|
delayed_job.identify(klass: "Delayed::Job") # => Delayed::Job[id:1]
|
|
87
90
|
```
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
### Nils and Empty Collections
|
|
90
93
|
|
|
91
94
|
```ruby
|
|
92
95
|
nil.identify(:id, :name) # => [no objects]
|
|
93
96
|
[].identify # => [no objects]
|
|
94
97
|
```
|
|
95
98
|
|
|
99
|
+
|
|
100
|
+
## Custom Object Identifiers
|
|
101
|
+
|
|
102
|
+
Internally, Object Identifier relies on a method named `inspect_lit` to return a "literally-inspected" string representation of all objects being identified. For example:
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
:a_symbol.respond_to?(:inspect_lit) # => true
|
|
106
|
+
:a_symbol.inspect_lit # => ":\"a_symbol\""
|
|
107
|
+
"a_string".inspect_lit # => "\"a_string\""
|
|
108
|
+
BigDecimal(1.99, 3).inspect_lit # => "<BD:1.99>"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Therefore, if you'd like to represent a custom object in a special way for object identification, just define the to-string conversion within the `inspect_lit` method.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
class MyVal
|
|
116
|
+
def initialize(val)
|
|
117
|
+
@val = val
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def inspect_lit
|
|
121
|
+
"<MOO:#{@val}>"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
OpenStruct.new(my_val: MyVal.new(42)).identify(:my_val)
|
|
126
|
+
# => "OpenStruct[my_val:<MOO:42>]"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
|
|
96
130
|
## Authors
|
|
97
131
|
|
|
98
132
|
- Paul Dobbins
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
class BigDecimal
|
|
2
|
-
# Formats this BigDecimal
|
|
3
|
-
#
|
|
2
|
+
# Formats this BigDecimal as an object-type-revealing String.
|
|
3
|
+
#
|
|
4
|
+
# @return [String] a String representation of this BigDecimal object
|
|
5
|
+
#
|
|
4
6
|
# @example
|
|
5
|
-
# BigDecimal.new(1).inspect_lit
|
|
7
|
+
# BigDecimal.new(1).inspect_lit # => "<BD:1.0>"
|
|
8
|
+
# BigDecimal.new(99.999, 5).inspect_lit # => "<BD:99.999>"
|
|
6
9
|
def inspect_lit
|
|
7
|
-
|
|
10
|
+
"<BD:#{self}>"
|
|
8
11
|
end
|
|
9
12
|
end
|
|
@@ -2,6 +2,7 @@ class Object
|
|
|
2
2
|
# Standard #inspect for any object that doesn't override this method. This
|
|
3
3
|
# method is meant to make an object's type inherently obvious when used in
|
|
4
4
|
# logging methods, etc.
|
|
5
|
+
#
|
|
5
6
|
# @return [String] a string representation of this object
|
|
6
7
|
def inspect_lit
|
|
7
8
|
inspect
|
|
@@ -9,21 +10,33 @@ class Object
|
|
|
9
10
|
|
|
10
11
|
# Instance method for constructing a self-identifying string for any given
|
|
11
12
|
# object or list of objects.
|
|
13
|
+
#
|
|
12
14
|
# @overload identify(*args)
|
|
13
15
|
# @param args [*] (optional) a list of arguments to identify for this object
|
|
14
16
|
# or for each object in this collection
|
|
15
17
|
# @overload identify(*args, options)
|
|
16
|
-
# @param args [*] (optional) (default: :id) a list of arguments to identify
|
|
17
|
-
#
|
|
18
|
+
# @param args [*] (optional) (default: :id) a list of arguments to identify
|
|
19
|
+
# for this object
|
|
20
|
+
# @param [Hash] options the options for building a customized
|
|
21
|
+
# self-identifier
|
|
18
22
|
# @option options [String, nil] :klass object class name override
|
|
19
|
-
# @option options [Fixnum] :limit maximum number of objects to display from
|
|
23
|
+
# @option options [Fixnum] :limit maximum number of objects to display from
|
|
24
|
+
# a collection
|
|
25
|
+
#
|
|
20
26
|
# @return [String] a self-identifying string like `Class[id:1, name:'temp']`
|
|
27
|
+
#
|
|
21
28
|
# @example
|
|
22
|
-
# OpenStruct.new(a: 1, b: '2', c: :"3").identify(:a, :b, :c)
|
|
29
|
+
# OpenStruct.new(a: 1, b: '2', c: :"3").identify(:a, :b, :c)
|
|
30
|
+
# # => "OpenStruct[a:1, b:\"2\", c::\"3\"]"
|
|
31
|
+
#
|
|
23
32
|
# 1.identify(:to_s) # => "Fixnum[to_s:\"1\"]"
|
|
24
|
-
# nil.identify
|
|
25
|
-
#
|
|
26
|
-
# (1
|
|
33
|
+
# nil.identify # => "[no objects]"
|
|
34
|
+
#
|
|
35
|
+
# %w(1 2 3).identify(:to_i, :to_f)
|
|
36
|
+
# # => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0], String[to_i:3, to_f:3.0]"
|
|
37
|
+
#
|
|
38
|
+
# (1..10).to_a.identify(:to_f, limit: 2)
|
|
39
|
+
# # => "Fixnum[to_f:1.0], Fixnum[to_f:2.0], ... (8 more)"
|
|
27
40
|
def identify(*args)
|
|
28
41
|
ObjectIdentifier::Identifier.identify(self, *args)
|
|
29
42
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
class String
|
|
2
2
|
# Formats this string to look like a string literal so that object type will
|
|
3
3
|
# be inherently obvious when used in logging methods, etc.
|
|
4
|
+
#
|
|
4
5
|
# @return [String] a string literal representation of this object
|
|
6
|
+
#
|
|
5
7
|
# @example
|
|
6
8
|
# "test".inspect_lit # => "\"test\"" (or '"test"')
|
|
7
|
-
# "1".inspect_lit
|
|
9
|
+
# "1".inspect_lit # => "\"1\"" (or '"1"')
|
|
8
10
|
# "12.3".inspect_lit # => "\"12.3\"" (or '"12.3"')
|
|
9
11
|
def inspect_lit
|
|
10
12
|
%("#{to_s}")
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
class Symbol
|
|
2
2
|
# Formats this symbol to look like a symbol literal so that object type will
|
|
3
3
|
# be inherently obvious when used in logging methods, etc.
|
|
4
|
+
#
|
|
4
5
|
# @return [String] a symbol literal representation of this object
|
|
6
|
+
#
|
|
5
7
|
# @example
|
|
6
|
-
# :test.inspect_lit
|
|
8
|
+
# :test.inspect_lit # => ":\"test\"" (or ':"test"')
|
|
7
9
|
# :"ta-da!".inspect_lit # => ":\"ta-da!\"" (or ':"ta-da!"')
|
|
8
10
|
def inspect_lit
|
|
9
11
|
%(:"#{to_s}")
|
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
require "naught"
|
|
2
|
-
|
|
3
1
|
module ObjectIdentifier
|
|
4
2
|
class Identifier
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
def initialize(objects, *args)
|
|
4
|
+
@objects = Array.wrap(objects)
|
|
5
|
+
@options = args.extract_options!
|
|
6
|
+
@attributes = args.empty? ? [:id] : args
|
|
7
|
+
end
|
|
7
8
|
|
|
8
9
|
# Class method for constructing a self-identifying string for any given
|
|
9
10
|
# object or collection of objects.
|
|
11
|
+
#
|
|
10
12
|
# @overload self.identify(obj, *args)
|
|
11
13
|
# @param obj [Object] the object to identify
|
|
12
|
-
# @param args [*] (optional) a list of arguments to identify for this
|
|
13
|
-
# or for each object in this collection
|
|
14
|
+
# @param args [*] (optional) a list of arguments to identify for this
|
|
15
|
+
# object or for each object in this collection
|
|
14
16
|
# @overload self.identify(obj, *args, options)
|
|
15
17
|
# @param obj [Object] the object to identify
|
|
16
|
-
# @param args [*] (optional) (default :id) a list of arguments to identify
|
|
17
|
-
#
|
|
18
|
+
# @param args [*] (optional) (default :id) a list of arguments to identify
|
|
19
|
+
# for this object
|
|
20
|
+
# @param [Hash] options the options for building a customized
|
|
21
|
+
# self-identifier
|
|
18
22
|
# @option options [String, nil] :klass object class name override
|
|
19
|
-
# @option options [Fixnum] :limit maximum number of objects to display
|
|
23
|
+
# @option options [Fixnum] :limit maximum number of objects to display
|
|
24
|
+
# from a collection
|
|
25
|
+
#
|
|
20
26
|
# @return [String] a self-identifying string like `Class[id:1, name:'temp']`
|
|
27
|
+
#
|
|
21
28
|
# @example
|
|
22
|
-
# ObjectIdentifier::Identifier.identify(OpenStruct.new(a: 1, b: '2', c: :"3"), :a, :b, :c)
|
|
29
|
+
# ObjectIdentifier::Identifier.identify(OpenStruct.new(a: 1, b: '2', c: :"3"), :a, :b, :c)
|
|
30
|
+
# # => "OpenStruct[a:1, b:\"2\", c::\"3\"]"
|
|
31
|
+
#
|
|
23
32
|
# ObjectIdentifier::Identifier.identify(1, :to_s) # => "Fixnum[to_s:\"1\"]"
|
|
24
|
-
# ObjectIdentifier::Identifier.identify(nil)
|
|
25
|
-
#
|
|
26
|
-
# ObjectIdentifier::Identifier.identify((1
|
|
33
|
+
# ObjectIdentifier::Identifier.identify(nil) # => "[no objects]"
|
|
34
|
+
#
|
|
35
|
+
# ObjectIdentifier::Identifier.identify(%w(1 2 3), :to_i, :to_f)
|
|
36
|
+
# # => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0], String[to_i:3, to_f:3.0]"
|
|
37
|
+
#
|
|
38
|
+
# ObjectIdentifier::Identifier.identify((1..10).to_a, :to_f, limit: 2)
|
|
39
|
+
# # => "Fixnum[to_f:1.0], Fixnum[to_f:2.0], ... (8 more)"
|
|
27
40
|
def self.identify(obj, *args)
|
|
28
|
-
new(
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def initialize(objects, *args)
|
|
32
|
-
@objects = objects
|
|
33
|
-
@options = args.extract_options!
|
|
34
|
-
@attributes = args.empty? ? [:id] : args
|
|
41
|
+
new(obj, *args).to_s
|
|
35
42
|
end
|
|
36
43
|
|
|
37
44
|
# Output the self-identifying string for an instance of
|
|
38
|
-
# ObjectIdentifier::Identifier. Will either return a single object
|
|
39
|
-
# or a list of object representations, based on the number of
|
|
40
|
-
# identifying.
|
|
45
|
+
# ObjectIdentifier::Identifier. Will either return a single object
|
|
46
|
+
# representation or a list of object representations, based on the number of
|
|
47
|
+
# objects we're identifying.
|
|
48
|
+
#
|
|
41
49
|
# @return [String] a string representing the object or list of objects
|
|
42
50
|
def to_s
|
|
43
51
|
if multiple_objects_to_identify?
|
|
@@ -51,8 +59,8 @@ module ObjectIdentifier
|
|
|
51
59
|
|
|
52
60
|
def format_multiple_objects
|
|
53
61
|
objects = @objects.first(limit).map do |obj|
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
format_with_attributes(obj)
|
|
63
|
+
end.join(", ")
|
|
56
64
|
|
|
57
65
|
if any_objects_abbreviated?
|
|
58
66
|
objects << ", ... (#{number_of_abbreviated_objects} more)"
|
|
@@ -71,15 +79,15 @@ module ObjectIdentifier
|
|
|
71
79
|
end
|
|
72
80
|
|
|
73
81
|
def multiple_objects_to_identify?
|
|
74
|
-
@objects.
|
|
82
|
+
@objects.many?
|
|
75
83
|
end
|
|
76
84
|
|
|
77
85
|
def limit
|
|
78
|
-
@options
|
|
86
|
+
@options.fetch(:limit) { @objects.size }.to_i
|
|
79
87
|
end
|
|
80
88
|
|
|
81
89
|
def limit_given?
|
|
82
|
-
@options.
|
|
90
|
+
@options.key?(:limit)
|
|
83
91
|
end
|
|
84
92
|
|
|
85
93
|
def any_objects_abbreviated?
|
|
@@ -87,7 +95,7 @@ module ObjectIdentifier
|
|
|
87
95
|
end
|
|
88
96
|
|
|
89
97
|
def number_of_abbreviated_objects
|
|
90
|
-
@objects.size -
|
|
98
|
+
@objects.size - @options[:limit].to_i
|
|
91
99
|
end
|
|
92
100
|
|
|
93
101
|
def format_with_attributes(object)
|
|
@@ -102,7 +110,7 @@ module ObjectIdentifier
|
|
|
102
110
|
end
|
|
103
111
|
|
|
104
112
|
def format_empty(object)
|
|
105
|
-
@options.
|
|
113
|
+
@options.key?(:klass) ? "#{@options[:klass]}[]" : "[no objects]"
|
|
106
114
|
end
|
|
107
115
|
|
|
108
116
|
def attribute_formatter(hash)
|
|
@@ -118,7 +126,7 @@ module ObjectIdentifier
|
|
|
118
126
|
end
|
|
119
127
|
|
|
120
128
|
def class_name_of(object)
|
|
121
|
-
@options.
|
|
129
|
+
@options.key?(:klass) ? @options[:klass] : object.class.name
|
|
122
130
|
end
|
|
123
131
|
end
|
|
124
132
|
end
|
|
@@ -2,68 +2,68 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
describe ObjectIdentifier::Identifier do
|
|
4
4
|
describe "#identify" do
|
|
5
|
-
it "yields 'Class[id:1]'
|
|
6
|
-
|
|
5
|
+
it "yields 'Class[id:1]', GIVEN id and no attributes" do
|
|
6
|
+
OpenStruct.new(id: 1).identify.must_equal "OpenStruct[id:1]"
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it "lists each entry in collection" do
|
|
10
10
|
collection = [OpenStruct.new(id: 1), OpenStruct.new(id: 2)]
|
|
11
|
-
|
|
11
|
+
collection.identify.must_equal "OpenStruct[id:1], OpenStruct[id:2]"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
describe "no attributes, no id, empty array, nil" do
|
|
15
|
-
it "yields 'Class[]'
|
|
16
|
-
|
|
15
|
+
it "yields 'Class[]', GIVEN no id or attributes" do
|
|
16
|
+
Object.new.identify.must_equal "Object[]"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
it "yields '[no objects]'
|
|
20
|
-
|
|
19
|
+
it "yields '[no objects]', GIVEN an empty array" do
|
|
20
|
+
[].identify.must_equal "[no objects]"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
it "yields '[no objects]'
|
|
24
|
-
|
|
23
|
+
it "yields '[no objects]', GIVEN nil" do
|
|
24
|
+
nil.identify.must_equal "[no objects]"
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
describe "with attributes" do
|
|
29
29
|
it "yields attribute values" do
|
|
30
30
|
obj = OpenStruct.new(name: "Pepper", beak_size: 4)
|
|
31
|
-
|
|
31
|
+
obj.identify(:beak_size).must_equal "OpenStruct[beak_size:4]"
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "quotes strings" do
|
|
35
35
|
obj = OpenStruct.new(name: "Pepper")
|
|
36
|
-
|
|
36
|
+
obj.identify(:name).must_equal %(OpenStruct[name:"Pepper"])
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "quotes symbols" do
|
|
40
40
|
obj = OpenStruct.new(name: "Pepper", color: :grey)
|
|
41
|
-
|
|
41
|
+
obj.identify(:color).must_equal %(OpenStruct[color::"grey"])
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "ignores attributes that don't exist" do
|
|
45
45
|
obj = OpenStruct.new(name: "Pepper", color: :grey, beak_size: 4)
|
|
46
|
-
|
|
46
|
+
obj.identify(:volume, :beak_size).must_equal "OpenStruct[beak_size:4]"
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
describe "options" do
|
|
51
51
|
it "overrides object class name with :klass" do
|
|
52
|
-
|
|
52
|
+
OpenStruct.new(id: 1).identify(klass: "Monkey").must_equal "Monkey[id:1]"
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
it "yields no class
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
it "yields no class, GIVEN class is empty string" do
|
|
56
|
+
OpenStruct.new(id: 1).identify(klass: "").must_equal "[id:1]"
|
|
57
|
+
OpenStruct.new(id: 1).identify(klass: nil).must_equal "[id:1]"
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it "overrides object class name with :klass with no attributes" do
|
|
61
|
-
|
|
61
|
+
[].identify(klass: "Monkey").must_equal "Monkey[]"
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it "yields first n (:limit) objects in collection" do
|
|
65
|
-
|
|
66
|
-
"Fixnum[to_i:1], Fixnum[to_i:2], Fixnum[to_i:3], ... (4 more)"
|
|
65
|
+
(1..7).to_a.identify(:to_i, limit: 3).must_equal(
|
|
66
|
+
"Fixnum[to_i:1], Fixnum[to_i:2], Fixnum[to_i:3], ... (4 more)")
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# Configure Rails Environment
|
|
2
1
|
ENV["RAILS_ENV"] = "test"
|
|
3
2
|
|
|
4
3
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
@@ -8,7 +7,7 @@ require "minitest/rails"
|
|
|
8
7
|
Rails.backtrace_cleaner.remove_silencers!
|
|
9
8
|
|
|
10
9
|
# Load support files
|
|
11
|
-
Dir[
|
|
10
|
+
Dir[Rails.root.join("test/support/**/*.rb")].each { |f| require f }
|
|
12
11
|
|
|
13
12
|
# Load fixtures from the engine
|
|
14
13
|
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: object_identifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Dobbins
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-08-
|
|
12
|
+
date: 2014-08-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -25,20 +25,6 @@ dependencies:
|
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: 3.0.0
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: naught
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - ">="
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: '0'
|
|
35
|
-
type: :runtime
|
|
36
|
-
prerelease: false
|
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
-
requirements:
|
|
39
|
-
- - ">="
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0'
|
|
42
28
|
- !ruby/object:Gem::Dependency
|
|
43
29
|
name: sqlite3
|
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -144,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
144
130
|
version: '0'
|
|
145
131
|
requirements: []
|
|
146
132
|
rubyforge_project:
|
|
147
|
-
rubygems_version: 2.
|
|
133
|
+
rubygems_version: 2.4.1
|
|
148
134
|
signing_key:
|
|
149
135
|
specification_version: 4
|
|
150
136
|
summary: Identify an object by inspecting its class name and attributes.
|