domino 0.10.0 → 0.11.0
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 -0
- data/domino.gemspec +1 -1
- data/lib/domino.rb +4 -4
- data/lib/domino/attribute.rb +14 -5
- data/test/domino_test.rb +15 -0
- 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: 2c529cedb0bb1da66235d1f520837cb40163bec1
|
4
|
+
data.tar.gz: 5835da7437f706398b60e3c19824dfda2af9d79a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ab5d6e5b9f270303d5d509e9b24d0e206bb0f33014d99ac56c5e676a37e165b2970e296ea83653f7938403517833607ac1402911cfb727d8e63b59a2904220b
|
7
|
+
data.tar.gz: 7558998f351960813f27050609f354dcdb96913382a98e238973a1329994fcd03ac965508cf3f4ac4fe1ae1b3f274ecb7b42d3defe82900d32da7945b5d54df2
|
data/README.md
CHANGED
@@ -48,6 +48,9 @@ Now in your integration test you can use some of Domino's methods:
|
|
48
48
|
assert_equal 4, Dom::Post.count
|
49
49
|
refute_nil Dom::Post.find_by_title('First Post')
|
50
50
|
|
51
|
+
# Find by attribute yields the node when using a block.
|
52
|
+
assert_equal Dom::Post.find_by_title { |node| node.text == "First Post" && node.tag_name == 'p' }
|
53
|
+
|
51
54
|
# Multiple attributes, returns first match if any
|
52
55
|
refute_nil Dom::Post.find_by(title: 'First Post', author: 'Jane Doe')
|
53
56
|
|
data/domino.gemspec
CHANGED
data/lib/domino.rb
CHANGED
@@ -146,8 +146,8 @@ class Domino
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
define_singleton_method :"find_by_#{attribute}" do |value|
|
150
|
-
find_by_attribute(attribute, value)
|
149
|
+
define_singleton_method :"find_by_#{attribute}" do |value = nil, &predicate|
|
150
|
+
find_by_attribute(attribute, value, &predicate)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -160,9 +160,9 @@ class Domino
|
|
160
160
|
end
|
161
161
|
|
162
162
|
# Internal method for finding nodes by a selector
|
163
|
-
def find_by_attribute(attribute, value)
|
163
|
+
def find_by_attribute(attribute, value = nil, &predicate)
|
164
164
|
detect do |domino|
|
165
|
-
attribute_definitions[attribute].match_value?(domino.node, value)
|
165
|
+
attribute_definitions[attribute].match_value?(domino.node, value, &predicate)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
data/lib/domino/attribute.rb
CHANGED
@@ -9,11 +9,14 @@ class Domino::Attribute
|
|
9
9
|
|
10
10
|
def value(node)
|
11
11
|
val = value_before_typecast(node)
|
12
|
+
convert(val)
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
def convert(value)
|
16
|
+
if value && callback.is_a?(Proc)
|
17
|
+
callback.call(value)
|
15
18
|
else
|
16
|
-
|
19
|
+
value
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
@@ -30,8 +33,14 @@ class Domino::Attribute
|
|
30
33
|
nil
|
31
34
|
end
|
32
35
|
|
33
|
-
def match_value?(node, value)
|
34
|
-
|
36
|
+
def match_value?(node, value = nil, &predicate)
|
37
|
+
if predicate.is_a?(Proc)
|
38
|
+
predicate.call(element(node))
|
39
|
+
else
|
40
|
+
node_value = value(node)
|
41
|
+
test_value = convert(value) rescue value
|
42
|
+
test_value === node_value
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
def element(node)
|
data/test/domino_test.rb
CHANGED
@@ -205,4 +205,19 @@ class DominoTest < Minitest::Test
|
|
205
205
|
person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
|
206
206
|
assert_equal 'h2', person.name(&:tag_name)
|
207
207
|
end
|
208
|
+
|
209
|
+
def test_find_by_with_unconverted_value_for_callback_computed_attribute
|
210
|
+
person = Dom::Person.find_by!(uuid: '05bf319e-8d6a-43c2-be37-2dad8ddbe5af')
|
211
|
+
assert_equal person.node, Dom::Person.find_by_age('52').node
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_find_by_with_converted_value_for_callback_computed_attribute
|
215
|
+
person = Dom::Person.find_by!(uuid: '05bf319e-8d6a-43c2-be37-2dad8ddbe5af')
|
216
|
+
assert_equal person.node, Dom::Person.find_by_age(52).node
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_find_by_with_converted_value_for_callback_computed_attribute_with_regex
|
220
|
+
person = Dom::Person.find_by!(uuid: '05bf319e-8d6a-43c2-be37-2dad8ddbe5af')
|
221
|
+
assert_equal person.node, Dom::Person.find_by_age { |age_node| age_node.text =~ /5[29]/ && age_node.tag_name == 'p' }.node
|
222
|
+
end
|
208
223
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Gauthier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|