site_prism-all_there 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a8336dc1b0631ca12cefaac99dbcc056d4f3711670647848f5d8a9d98e5bd17c
4
+ data.tar.gz: 61f56cfd1073989ae922c244236d732fce4395053db7e9ac05e500834da290c5
5
+ SHA512:
6
+ metadata.gz: c40aa2a060d407a3f38781627a3d8ca5294025add8b05a7118896a574835144e4835a2394cc51988435b0937882271c6cadb4d4f69fb7c9d87d851846b6461b9
7
+ data.tar.gz: 96eeb9d5e0fbc82042bff60f88e4146581cad2329a135ec2179aff4c6d5b53ba271b87f3648b65670903c600d475d913957485b950b33b18d4e8ff7d95ff9880
data/LICENSE.md ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2018-2019, The SitePrism team
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its contributors
16
+ may be used to endorse or promote products derived from this software without
17
+ specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
25
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # site_prism-all_there
2
+ The breakout gem from SitePrism to perform recursion checks for all_there?
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SitePrism
4
+ module AllThere
5
+ class RecursionChecker
6
+ attr_reader :instance
7
+ private :instance
8
+
9
+ def initialize(instance)
10
+ @instance = instance
11
+ end
12
+
13
+ def all_there?
14
+ regular_items_all_there = expected_item_map.flatten.all? { |name| there?(name) }
15
+ return false unless regular_items_all_there
16
+
17
+ section_all_there =
18
+ section_classes_to_check.all?(&:all_there?)
19
+ return false unless section_all_there
20
+
21
+ # Returning this final check here is fine, as the previous two checks must
22
+ # have returned +true+ in order to hit this part of the method-call
23
+ sections_classes_to_check.all?(&:all_there?)
24
+ end
25
+
26
+ def expected_item_map
27
+ [
28
+ expected(mapped_items, :element),
29
+ expected(mapped_items, :elements),
30
+ expected(mapped_items, :section),
31
+ expected(mapped_items, :sections),
32
+ expected(mapped_items, :iframe),
33
+ ]
34
+ end
35
+
36
+ def expected(map, type)
37
+ map[type].select { |name| elements_to_check.include?(name) }
38
+ end
39
+
40
+ def section_classes_to_check
41
+ expected_item_map[2].map { |name| instance.send(name) }
42
+ end
43
+
44
+ def sections_classes_to_check
45
+ expected_item_map[3].map { |name| instance.send(name) }.flatten
46
+ end
47
+
48
+ private
49
+
50
+ # If the page or section has expected_items set, return expected_items that are mapped
51
+ # otherwise just return the list of all mapped_items
52
+ def elements_to_check
53
+ if _expected_items
54
+ SitePrism.logger.debug('Expected Items has been set.')
55
+ _mapped_items.select { |name| _expected_items.include?(name) }
56
+ else
57
+ _mapped_items
58
+ end
59
+ end
60
+
61
+ def _mapped_items
62
+ mapped_items.values.flatten.uniq
63
+ end
64
+
65
+ def _expected_items
66
+ instance.class.expected_items
67
+ end
68
+
69
+ def there?(name)
70
+ instance.send("has_#{name}?")
71
+ end
72
+
73
+ def mapped_items
74
+ @mapped_items ||= instance.class.mapped_items(legacy: false)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SitePrism
4
+ module AllThere
5
+ VERSION = '0.1'
6
+ end
7
+ end
data/lib/site_prism.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SitePrism
4
+ autoload :RecursionChecker, 'site_prism/all_there/recursion_checker'
5
+
6
+ class << self
7
+ attr_writer :recursion_setting
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+
13
+ def recursion_setting
14
+ @recursion_setting ||= :none
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: site_prism-all_there
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Luke Hill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.67.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.67.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-performance
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: site_prism
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ description: |-
84
+ SitePrism AllThere gives you a simple DSL in order to recursively query,
85
+ page/section/element structures on your page - exclusively for use with the SitePrism gem.
86
+ email:
87
+ - lukehill_uk@hotmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - LICENSE.md
93
+ - README.md
94
+ - lib/site_prism.rb
95
+ - lib/site_prism/all_there/recursion_checker.rb
96
+ - lib/site_prism/all_there/version.rb
97
+ homepage: https://github.com/site_prism/site_prism-all_there
98
+ licenses:
99
+ - BSD-3-Clause
100
+ metadata:
101
+ bug_tracker_uri: https://github.com/site_prism/site_prism-all_there/issues
102
+ changelog_uri: https://github.com/site_prism/site_prism-all_there/blob/master/CHANGELOG.md
103
+ source_code_uri: https://github.com/site_prism/site_prism-all_there
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '2.3'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.7.8
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: 'An extension to SitePrism to allow you to use recursive checks on #all_there?'
124
+ test_files: []