swamp 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.ruby-version +1 -0
  4. data/Guardfile +33 -0
  5. data/README.md +24 -10
  6. data/features/specifications/changing_scope_to_source.feature +16 -0
  7. data/features/specifications/scope_changing.feature +14 -24
  8. data/features/specifications/using_prism_scope.feature +100 -0
  9. data/features/step_definitions/swamp_steps.rb +14 -4
  10. data/lib/swamp/builders/basic.rb +39 -0
  11. data/lib/swamp/builders/prism.rb +9 -0
  12. data/lib/swamp/collections/buttons.rb +28 -0
  13. data/lib/swamp/{fields.rb → collections/fields.rb} +9 -3
  14. data/lib/swamp/{input_buttons.rb → collections/input_buttons.rb} +7 -2
  15. data/lib/swamp/{links.rb → collections/links.rb} +3 -1
  16. data/lib/swamp/collections/select_boxes.rb +28 -0
  17. data/lib/swamp/{button.rb → elements/button.rb} +1 -0
  18. data/lib/swamp/{complex_select_box.rb → elements/complex_select_box.rb} +2 -0
  19. data/lib/swamp/{element.rb → elements/element.rb} +12 -0
  20. data/lib/swamp/{field.rb → elements/field.rb} +1 -0
  21. data/lib/swamp/{input_button.rb → elements/input_button.rb} +1 -0
  22. data/lib/swamp/{link.rb → elements/link.rb} +1 -0
  23. data/lib/swamp/{select_box.rb → elements/select_box.rb} +1 -0
  24. data/lib/swamp/scopes/page.rb +9 -0
  25. data/lib/swamp/scopes/prism.rb +9 -0
  26. data/lib/swamp/scopes/scope.rb +13 -0
  27. data/lib/swamp/scopes/source.rb +9 -0
  28. data/lib/swamp/setup.rb +7 -3
  29. data/lib/swamp/version.rb +1 -1
  30. data/lib/swamp/wrapper.rb +1 -1
  31. data/lib/swamp.rb +19 -14
  32. data/spec/swamp/builders/basic_spec.rb +44 -0
  33. data/spec/swamp/builders/prism_spec.rb +17 -0
  34. data/spec/swamp/buttons_spec.rb +7 -4
  35. data/spec/swamp/fields_spec.rb +3 -0
  36. data/spec/swamp/input_buttons_spec.rb +1 -0
  37. data/spec/swamp/links_spec.rb +1 -0
  38. data/spec/swamp/select_boxes_spec.rb +3 -0
  39. data/spec/swamp/setup_spec.rb +11 -4
  40. data/swamp.gemspec +12 -10
  41. metadata +96 -55
  42. data/lib/swamp/builder.rb +0 -39
  43. data/lib/swamp/buttons.rb +0 -22
  44. data/lib/swamp/select_boxes.rb +0 -22
  45. data/spec/swamp/builder_spec.rb +0 -46
  46. /data/lib/swamp/{elements.rb → collections/elements.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 321488f9c4e58a1213185e05bce1473a6777bf6d
4
- data.tar.gz: 929ab8a776d0303b5c211b1cd9e0787435d6ebd5
3
+ metadata.gz: d75a81ad2f5980818dc56e8a9142268169597d0a
4
+ data.tar.gz: 762d89066107e05871ef922878edc4127cbb7d26
5
5
  SHA512:
6
- metadata.gz: 3f9c38ba1d09493db01a42820a7befd550ba1d0b8d7fd20dc72d5423e81ea37e0a31e9415075a5a9441439c6bed341b6596ed3c3fe6b945466250c0c74caa317
7
- data.tar.gz: 5324834c433679cf9a7409ceac75d3f9f4d886e759d1db0b8ce249e8714e4766aa4f5869b763d9d776272009b7519c560d5db135687e819fb78d7feab97018ec
6
+ metadata.gz: 8487ad90dd5a1a27c3afa5678fbb39884a7517832cb062cc26c06aa4378fa475eedade961a6efa4b4ed48d9abfe5aa710f200fde997675453c783bcf081dae41
7
+ data.tar.gz: dad587976af09e6837e65dbd0ae6951733839b94f5120ce03416ebe39350bdea58679b3d856de119c4a0615e0c1a8e17a0c0cea1702e14a66804909577b1b7fa
data/.gitignore CHANGED
@@ -13,8 +13,9 @@ test/tmp
13
13
  test/version_tmp
14
14
  tmp
15
15
  *.swp
16
+ .idea/
16
17
 
17
18
  # YARD artifacts
18
19
  .yardoc
19
20
  _yardoc
20
- doc/
21
+ doc/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.1
data/Guardfile ADDED
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
data/README.md CHANGED
@@ -68,8 +68,6 @@ end
68
68
  module PageObjects
69
69
  class SignIn
70
70
 
71
- path ""
72
-
73
71
  def type_email(input)
74
72
  page.fill_in("Email", with: input)
75
73
  end
@@ -108,15 +106,20 @@ When /^I attempt to sign in with valid credentials/ do
108
106
  end
109
107
  ```
110
108
 
111
- ### Dynamically detecting elements
109
+ ### Generating code snippets to use with [SitePrism](https://github.com/natritmeyer/site_prism)
110
+
111
+ You can easily change the scope from "page" to "prism" by using the following command:
112
+
113
+ ```shell
114
+ :scope = prism
115
+ ```
116
+
117
+ then the code snippets will be generated in the SitePrism fromat:
118
+
119
+ ```shell
120
+ element :sign_up, 'button', text: 'Sign Up'
121
+ ```
112
122
 
113
- * You can navigate in the browser that swamp opens
114
- * Lets say you need to log in to have access to some page
115
- * Just enter the url for this page
116
- * Do the login procedure in the oppened browser manually
117
- * Wait for the new page to load
118
- * Then just go to the terminal and hit ENTER
119
- * Swamp will detect the new elements (if any) and will generate the code snippets the same way as before
120
123
 
121
124
  ### Generating code snippets to use with [capybara-page-object](https://github.com/andyw8/capybara-page-object)
122
125
 
@@ -134,6 +137,17 @@ then the code snippets will be generated with the "source" scope like this:
134
137
  end
135
138
  ```
136
139
 
140
+ ### Dynamically detecting elements
141
+
142
+ You can navigate in the browser that swamp opens. Lets say a page that you want to scan requires login, then just do the following:
143
+
144
+ * Enter the url for this page on swamp and wait for the page to load
145
+ * Do the login procedure in the oppened browser manually
146
+ * Wait for the new page to load
147
+ * Then just go to the terminal and hit ENTER
148
+ * Swamp will detect the new elements (if any) and will generate the code snippets the same way as before
149
+
150
+
137
151
  ## How it works?
138
152
 
139
153
  It uses capybara to fireup the browser and visit the target URL then it looks for patterns like:
@@ -0,0 +1,16 @@
1
+ Feature: User chooses the source scope
2
+
3
+ As a Swamp user
4
+ I want to change the scope to "source"
5
+ So I can have snippets that are compatible with capybara-page-object gem
6
+
7
+ Scenario: User changes the scope from page to source
8
+ Given that swamp is already running
9
+ When I attempt to execute the command ":scope = source"
10
+ And I attempt to scan this page: "button.html"
11
+ Then swamp should output the following code snippet
12
+ """
13
+ def sign_up
14
+ source.click_button("Sign Up")
15
+ end
16
+ """
@@ -1,34 +1,24 @@
1
1
  Feature: user changes the scope in the runtime
2
2
 
3
3
  As a swamp user
4
- I want to change the scope from "page" to "source"
5
- So I can have snippets that are compatible with capybara-page-object gem
4
+ I want to change Swamp's scope
5
+ So I can have snippets that are compatible me favorite framework
6
6
 
7
7
  Scenario Outline: User receives feedback from swamp on command execution
8
8
  Given that swamp is already running
9
9
  When I attempt to execute the command <command>
10
10
  Then I should see <expected>
11
11
 
12
- Examples: Happy paths
13
- | command | expected |
14
- | ":scope = source" | "Option :scope set to source" |
15
- | ":scope = page" | "Option :scope set to page" |
12
+ Examples: Happy paths
13
+ | command | expected |
14
+ | ":scope = source" | "Option :scope set to source" |
15
+ | ":scope = page" | "Option :scope set to page" |
16
+ | ":scope = prism" | "Option :scope set to prism" |
16
17
 
17
- Examples: Corner cases
18
- | command | expected |
19
- | ":scope=source" | "Option :scope set to source" |
20
- | ":scope = page" | "Option :scope set to page" |
21
- | ":scope = " | "Invalid command" |
22
- | ":whatever = random" | "Invalid command" |
23
- | ": = " | "Invalid command" |
24
-
25
- Scenario: User changes the scope from page to source
26
- Given that swamp is already running
27
- When I attempt to execute the command ":scope = source"
28
- And I attempt to scan this page: "button.html"
29
- Then swamp should output the following code snippet
30
- """
31
- def sign_up
32
- source.click_button("Sign Up")
33
- end
34
- """
18
+ Examples: Corner cases
19
+ | command | expected |
20
+ | ":scope=source" | "Option :scope set to source" |
21
+ | ":scope = page" | "Option :scope set to page" |
22
+ | ":scope = " | "Invalid command" |
23
+ | ":whatever = random" | "Invalid command" |
24
+ | ": = " | "Invalid command" |
@@ -0,0 +1,100 @@
1
+ Feature: User chooses the prism scope
2
+
3
+ As a Swamp user
4
+ I want to change the scope to "prism"
5
+ So that I have snippets compatible with SitePrism page object
6
+
7
+ Background: Swamp is running using prism scope
8
+ Given that swamp is already running
9
+ And its using "prism" scope
10
+
11
+ Scenario: Scanning a button which has text
12
+ When swamp scan this page: "button.html"
13
+ Then it should output the following code snippet
14
+ """
15
+ element :sign_up, 'button', text: 'Sign Up'
16
+ """
17
+
18
+ Scenario: Scanning a button that doesn't has text but has id
19
+ When swamp scan this page: "button_without_text.html"
20
+ Then it should output the following code snippet
21
+ """
22
+ element :search_button, '#search-button'
23
+ """
24
+
25
+ Scenario: Scanning a button that doesn't has either text or id but has the value attribute
26
+ When swamp scan this page: "button_without_text_without_id_with_value.html"
27
+ Then it should output the following code snippet
28
+ """
29
+ element :buy_now, "[value='buy-now']"
30
+ """
31
+
32
+ Scenario: Scanning an input that has id, name and whose the type is text
33
+ When swamp scan this page: "field.html"
34
+ Then it should output the following code snippet
35
+ """
36
+ element :username, '#id_username'
37
+ """
38
+
39
+ Scenario: Scanning an input that has no name, has id and whose the type is text
40
+ When swamp scan this page: "field_without_name.html"
41
+ Then it should output the following code snippet
42
+ """
43
+ element :username, '#username'
44
+ """
45
+
46
+ Scenario: Scanning an input without the id attribute that has name and the type is text
47
+ When swamp scan this page: "field_without_id.html"
48
+ Then it should output the following code snippet
49
+ """
50
+ element :username, 'input[name="username"]'
51
+ """
52
+
53
+ Scenario: Scanning a submit that has value and id
54
+ When swamp scan this page: "input_submit.html"
55
+ Then it should output the following code snippet
56
+ """
57
+ element :log_in, '#u_0_b'
58
+ """
59
+
60
+ Scenario: Scanning a submit that has no id
61
+ When swamp scan this page: "input_submit_without_id.html"
62
+ Then it should output the following code snippet
63
+ """
64
+ element :continue, "input.button.g-button.g-button-submit[value='Continue']"
65
+ """
66
+ Scenario: Scanning a link that has id
67
+ When swamp scan this page: "link_with_id.html"
68
+ Then it should output the following code snippet
69
+ """
70
+ element :link_forgot_passwd, '#link-forgot-passwd'
71
+ """
72
+
73
+ Scenario: Scanning a select box that has id
74
+ When swamp scan this page: "select_box_with_id.html"
75
+ Then it should output the following code snippet
76
+ """
77
+ element :month, '#month'
78
+ """
79
+ Scenario: Scanning a select box that has name only
80
+ When swamp scan this page: "select_box_with_name_only.html"
81
+ Then it should output the following code snippet
82
+ """
83
+ element :region, "select[name='Region']"
84
+ """
85
+
86
+ Scenario: Scanning a select box that doesn't has either id or name
87
+ When swamp scan this page: "select_without_id_and_name.html"
88
+ Then it should output the following code snippet
89
+ """
90
+ element :provider_select, 'select.provider-select'
91
+ """
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
@@ -1,15 +1,15 @@
1
- Given /^swamp is not yet running$/ do
1
+ Given /^swamp is not yet running$/ do
2
2
  end
3
3
 
4
- When /^(?:I start it|that swamp is already running)$/ do
4
+ When /^(?:I start it|that swamp is already running)$/ do
5
5
  swamp.run
6
6
  end
7
7
 
8
- Then /^I should see "(.*?)"$/ do |outcome|
8
+ Then /^I should see "(.*?)"$/ do |outcome|
9
9
  fake_output.messages.should include(outcome)
10
10
  end
11
11
 
12
- Given /^I enter the url for this page: "(\w+\.html)"$/ do |page|
12
+ Given /^I enter the url for this page: "(\w+\.html)"$/ do |page|
13
13
  path = File.join(File.dirname(__FILE__), '../support/page_examples/', page)
14
14
  @url = "file://#{path}"
15
15
  end
@@ -69,3 +69,13 @@ end
69
69
  When /^I attempt to execute the command "(.*?)"$/ do |command|
70
70
  swamp.setup_command(command)
71
71
  end
72
+
73
+ Given(/^its using "(.*?)" scope$/) do |scope|
74
+ swamp.setup_command(":scope = #{scope}")
75
+ end
76
+
77
+ When(/^swamp scan this page: "(.*?)"$/) do |page|
78
+ path = File.join(File.dirname(__FILE__), '../support/page_examples/', page)
79
+ @url = "file://#{path}"
80
+ swamp.scan(@url)
81
+ end
@@ -0,0 +1,39 @@
1
+ module Swamp
2
+ module Builders
3
+ class Basic
4
+
5
+ def initialize(base)
6
+ @base = base
7
+ end
8
+
9
+ def build_snippet(element)
10
+ if element.name
11
+ [method_definition, element.method_signature, line_break, identation, base, element.accessor, line_break, method_end].join
12
+ else
13
+ [base, element.accessor].join
14
+ end
15
+ end
16
+
17
+ def method_definition
18
+ 'def '
19
+ end
20
+
21
+
22
+ def method_end
23
+ 'end'
24
+ end
25
+
26
+ def base
27
+ [@base, '.'].join
28
+ end
29
+
30
+ def identation
31
+ ' '
32
+ end
33
+
34
+ def line_break
35
+ "\n"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module Swamp
2
+ module Builders
3
+ class Prism
4
+ def build_snippet element
5
+ "element :#{element.formatted_name}, #{element.prism_selector}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module Swamp
2
+ class Buttons < Elements
3
+ def get
4
+ elements = []
5
+ page.all('button').map do |element|
6
+ if element.visible?
7
+ if has_valid_text?(element)
8
+ shine %\//button[text()='#{element.text}']\, :xpath
9
+ button = Swamp::Button.new(element.text, element.text)
10
+ button.prism_selector = %\'button', text: '#{element.text}'\
11
+ elements << button
12
+ elsif has_id?(element) and has_valid_id?(element)
13
+ shine %/##{element['id']}/
14
+ button = Swamp::Button.new(element['id'], element['id'])
15
+ button.prism_selector = "'##{element['id']}'"
16
+ elements << button
17
+ elsif has_value?(element) and has_valid_value?(element)
18
+ shine %/button[value='#{element['value']}']/
19
+ button = Swamp::Button.new(element['value'], element['value'])
20
+ button.prism_selector = %\"[value='#{element['value']}']"\
21
+ elements << button
22
+ end
23
+ end
24
+ end
25
+ elements
26
+ end
27
+ end
28
+ end
@@ -6,13 +6,19 @@ module Swamp
6
6
  if element.visible? and valid_type?(element)
7
7
  if has_id?(element) and has_name?(element)
8
8
  shine %/##{element['id']}/
9
- elements << Swamp::Field.new(element['name'], element['id'])
9
+ field = Swamp::Field.new(element['name'], element['id'])
10
+ field.prism_selector = "'##{element['id']}'"
11
+ elements << field
10
12
  elsif has_id?(element)
11
13
  shine %/##{element['id']}/
12
- elements << Swamp::Field.new(element['id'], element['id'])
14
+ field = Swamp::Field.new(element['id'], element['id'])
15
+ field.prism_selector = "'##{element['id']}'"
16
+ elements << field
13
17
  elsif has_name?(element)
14
18
  shine %/input[name=#{element['name']}]/
15
- elements << Swamp::Field.new(element['name'], element['name'])
19
+ field = Swamp::Field.new(element['name'], element['name'])
20
+ field.prism_selector = %/'input[name="#{element['name']}"]'/
21
+ elements << field
16
22
  end
17
23
  end
18
24
  end
@@ -7,10 +7,15 @@ module Swamp
7
7
  if has_value?(element)
8
8
  if has_id?(element)
9
9
  shine %/##{element["id"]}/
10
- elements << Swamp::InputButton.new(element["value"], "##{element["id"]}")
10
+ button = Swamp::InputButton.new(element["value"], "##{element["id"]}")
11
+ button.prism_selector = %\'##{element['id']}'\
12
+ elements << button
11
13
  elsif has_class?(element)
12
14
  shine %/input.#{formatter.format_class(element["class"])}[value='#{element["value"]}']/
13
- elements << Swamp::InputButton.new(element["value"], "input.#{formatter.format_class(element["class"])}[value='#{element["value"]}']")
15
+ capybara_selector = "input.#{formatter.format_class(element["class"])}[value='#{element["value"]}']"
16
+ button = Swamp::InputButton.new(element["value"], capybara_selector)
17
+ button.prism_selector = %\"#{capybara_selector}"\
18
+ elements << button
14
19
  end
15
20
  end
16
21
  end
@@ -5,7 +5,9 @@ module Swamp
5
5
  page.all('a[href][id]').map do | element |
6
6
  if element.visible?
7
7
  shine_link %/##{element["id"]}/
8
- elements << Swamp::Link.new(element["id"], element["id"])
8
+ link = Swamp::Link.new(element["id"], element["id"])
9
+ link.prism_selector = "'##{element['id']}'"
10
+ elements << link
9
11
  end
10
12
  end
11
13
  elements
@@ -0,0 +1,28 @@
1
+ module Swamp
2
+ class SelectBoxes < Elements
3
+ def get
4
+ elements = []
5
+ page.all('select').map do | element |
6
+ if element.visible?
7
+ if has_id?(element)
8
+ shine %/##{element["id"]}/
9
+ select_box = Swamp::SelectBox.new(element["id"], element["id"])
10
+ select_box.prism_selector = "'##{element['id']}'"
11
+ elements << select_box
12
+ elsif has_name?(element)
13
+ shine %/select[name='#{element["name"]}']/
14
+ select_box = Swamp::SelectBox.new(element["name"], element["name"])
15
+ select_box.prism_selector = %\"select[name='#{element['name']}']"\
16
+ elements << select_box
17
+ else
18
+ shine %/select.#{element["class"]}/
19
+ select_box = Swamp::ComplexSelectBox.new(element["class"], element["class"])
20
+ select_box.prism_selector = %\'select.#{element['class']}'\
21
+ elements << select_box
22
+ end
23
+ end
24
+ end
25
+ elements
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,6 @@
1
1
  module Swamp
2
2
  class Button < Element
3
+ attr_accessor :prism_selector
3
4
  def method_signature
4
5
  format(@name)
5
6
  end
@@ -1,5 +1,7 @@
1
1
  module Swamp
2
2
  class ComplexSelectBox < Element
3
+ attr_accessor :prism_selector
4
+
3
5
  def method_signature
4
6
  "#{format(@name)}(option)"
5
7
  end
@@ -16,6 +16,18 @@ module Swamp
16
16
  raise NotImplementedError, "Must be implemented by subtypes"
17
17
  end
18
18
 
19
+ def prism_selector
20
+ raise NotImplementedError, "Must be implemented by subtypes"
21
+ end
22
+
23
+ def prism_selector=(value)
24
+ raise NotImplementedError, "Must be implemented by subtypes"
25
+ end
26
+
27
+ def formatted_name
28
+ format(name)
29
+ end
30
+
19
31
  def format(text)
20
32
  Swamp::Formatter.new.format(text)
21
33
  end
@@ -1,5 +1,6 @@
1
1
  module Swamp
2
2
  class Field < Element
3
+ attr_accessor :prism_selector
3
4
  def method_signature
4
5
  "type_#{format(@name)}(input)"
5
6
  end
@@ -1,5 +1,6 @@
1
1
  module Swamp
2
2
  class InputButton < Element
3
+ attr_accessor :prism_selector
3
4
  def method_signature
4
5
  format(@name)
5
6
  end
@@ -1,5 +1,6 @@
1
1
  module Swamp
2
2
  class Link < Element
3
+ attr_accessor :prism_selector
3
4
  def method_signature
4
5
  format(@name)
5
6
  end
@@ -1,5 +1,6 @@
1
1
  module Swamp
2
2
  class SelectBox < Element
3
+ attr_accessor :prism_selector
3
4
  def method_signature
4
5
  "select_#{format(@name)}(option)"
5
6
  end
@@ -0,0 +1,9 @@
1
+ module Swamp
2
+ module Scope
3
+ class Page
4
+ def builder
5
+ @builder ||= Swamp::Builders::Basic.new('page')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Swamp
2
+ module Scope
3
+ class Prism
4
+ def builder
5
+ @builder ||= Swamp::Builders::Prism.new
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Swamp
2
+ module Scope
3
+
4
+ SCOPES = {
5
+ source: Swamp::Scope::Source.new,
6
+ page: Swamp::Scope::Page.new,
7
+ prism: Swamp::Scope::Prism.new
8
+ }
9
+ def Scope.from_value(value)
10
+ SCOPES[value.to_sym]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Swamp
2
+ module Scope
3
+ class Source
4
+ def builder
5
+ @builder ||= Swamp::Builders::Basic.new('source')
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/swamp/setup.rb CHANGED
@@ -3,13 +3,13 @@ module Swamp
3
3
  attr_reader :scope
4
4
 
5
5
  COMMAND_LIST = {
6
- ":scope" => ["source", "page"]
6
+ ":scope" => ["source", "page", "prism"]
7
7
  }
8
8
 
9
9
  include Swamp::Assertions
10
10
 
11
11
  def initialize
12
- @scope = "page"
12
+ @scope = Swamp::Scope.from_value('page')
13
13
  end
14
14
 
15
15
  def handle_command(input)
@@ -22,11 +22,15 @@ module Swamp
22
22
  return ["Invalid command"]
23
23
  end
24
24
 
25
- @scope = value
25
+ @scope = Swamp::Scope.from_value(value)
26
26
 
27
27
  [success_message]
28
28
  end
29
29
 
30
+ def builder
31
+ @scope.builder
32
+ end
33
+
30
34
  private
31
35
 
32
36
  def success_message
data/lib/swamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swamp
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
data/lib/swamp/wrapper.rb CHANGED
@@ -18,7 +18,7 @@ module Swamp
18
18
  def scan
19
19
  found_snippets = []
20
20
  @meta_collection.each do | element_collection |
21
- found_snippets += element_collection.get.map { | element | Swamp::Builder.new(element, @setup).build_snippet }
21
+ found_snippets += element_collection.get.map { | element | @setup.builder.build_snippet(element) }
22
22
  end
23
23
  found_snippets
24
24
  end