screengem 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop +1 -0
- data/.rubocop.yml +58 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/screengem +8 -0
- data/bin/setup +8 -0
- data/lib/screengem/action.rb +9 -0
- data/lib/screengem/actor.rb +86 -0
- data/lib/screengem/browser_action.rb +7 -0
- data/lib/screengem/cli.rb +32 -0
- data/lib/screengem/concerns/actionable.rb +29 -0
- data/lib/screengem/concerns/configurable.rb +18 -0
- data/lib/screengem/concerns/dampenable.rb +45 -0
- data/lib/screengem/concerns/executable.rb +15 -0
- data/lib/screengem/configuration.rb +63 -0
- data/lib/screengem/dampen_configuration.rb +85 -0
- data/lib/screengem/dampen_configuration_generator.rb +57 -0
- data/lib/screengem/dsl.rb +14 -0
- data/lib/screengem/factories/action_factory.rb +34 -0
- data/lib/screengem/factories/browser_action_factory.rb +14 -0
- data/lib/screengem/factories/factory_creation_error.rb +18 -0
- data/lib/screengem/factories/question_factory.rb +38 -0
- data/lib/screengem/factories/standard_action_factory.rb +14 -0
- data/lib/screengem/factories/task_factory.rb +38 -0
- data/lib/screengem/feature_page.rb +8 -0
- data/lib/screengem/incorrect_answer.rb +23 -0
- data/lib/screengem/page_references.rb +42 -0
- data/lib/screengem/primitive_key.rb +10 -0
- data/lib/screengem/question.rb +16 -0
- data/lib/screengem/screengem_error.rb +3 -0
- data/lib/screengem/task.rb +19 -0
- data/lib/screengem/version.rb +3 -0
- data/lib/screengem.rb +47 -0
- data/screengem.gemspec +34 -0
- metadata +212 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c867245700998e61a1a4267fa2310d0969c7a18090fd833005976dfe358094aa
|
4
|
+
data.tar.gz: bb153e7f607790113e9623fc923e6a105db61fd46e433a85c830585db571fe3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 556786b3992d74be2e1c28ea53b53fa7e8f50012828bc46bc523502dd8711cfadf2142cdc06d20b444e5a4fe91fcb9ad3eeb3ebe45a996775b4aeb3f1c7c6088
|
7
|
+
data.tar.gz: e08be7f02fff0f28daa21ec772beb2face609a17c777aabc773e88c39bc7d55942d65756c87eb75fbc297532fa2531ca2fd4de08976e51708d703cb354a8552e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--display-cop-names
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
Metrics/AbcSize:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 120
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
RSpec/AnyInstance:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
RSpec/ExampleLength:
|
19
|
+
Max: 20
|
20
|
+
|
21
|
+
RSpec/MultipleExpectations:
|
22
|
+
Max: 5
|
23
|
+
|
24
|
+
RSpec/LeadingSubject:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
RSpec/MessageSpies:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/NotToNot:
|
31
|
+
EnforcedStyle: to_not
|
32
|
+
|
33
|
+
Style/Documentation:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/EmptyMethod:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/FrozenStringLiteralComment:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/MutableConstant:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/ExpandPathArguments:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/StringLiterals:
|
49
|
+
EnforcedStyle: double_quotes
|
50
|
+
|
51
|
+
Style/RescueModifier:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Style/RescueStandardError:
|
55
|
+
EnforcedStyle: implicit
|
56
|
+
|
57
|
+
Style/WordArray:
|
58
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.3
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alistairm@nulogy.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Alistair McKinnell
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Screengem
|
2
|
+
|
3
|
+
A simple Ruby implementation of the [Screenplay Pattern](https://ideas.riverglide.com/page-objects-refactored-12ec3541990).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'screengem'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
TODO: Write usage instructions here
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
20
|
+
|
21
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nulogy/screengem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
30
|
+
|
31
|
+
## Code of Conduct
|
32
|
+
|
33
|
+
Everyone interacting in the Screengem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nulogy/screengem/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "screengem"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/screengem
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Screengem
|
2
|
+
#
|
3
|
+
# Mixin that allows an actor to perform tasks, ask questions, take actions, and
|
4
|
+
# to remember and recall tagged values.
|
5
|
+
#
|
6
|
+
# Return self for those methods that may be chained in the step definition DSL.
|
7
|
+
#
|
8
|
+
# The ability to remember and recall values is used to carry state forward from one
|
9
|
+
# step definition to another (as the preferred alternative to instance variables).
|
10
|
+
#
|
11
|
+
# Action, question, and task instances are extended with PageReferences so that
|
12
|
+
# they can interact with the application via page objects.
|
13
|
+
#
|
14
|
+
module Actor
|
15
|
+
#
|
16
|
+
# Used by an actor to ask one or more questions in a step definition.
|
17
|
+
#
|
18
|
+
def asks(*questions)
|
19
|
+
questions.each do |question|
|
20
|
+
question.configure(self).extend(page_references)
|
21
|
+
|
22
|
+
next if question.answer
|
23
|
+
|
24
|
+
raise incorrect_answer(question)
|
25
|
+
end
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Used by an actor to perform one or more tasks in a step definition.
|
32
|
+
#
|
33
|
+
def performs(*tasks)
|
34
|
+
tasks.each do |task|
|
35
|
+
task.configure(self).extend(page_references)
|
36
|
+
|
37
|
+
task.perform
|
38
|
+
end
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Used by an actor to recall a value for the specified tag.
|
45
|
+
#
|
46
|
+
def recall(tag)
|
47
|
+
recollections.fetch(tag)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Used by an actor to remember one or more tagged values.
|
52
|
+
#
|
53
|
+
def remember(facts)
|
54
|
+
recollections.merge!(facts)
|
55
|
+
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Used by an actor to take one or more actions.
|
61
|
+
#
|
62
|
+
# Used to implement tasks. Actions do not appear in step definitions.
|
63
|
+
#
|
64
|
+
def takes_action(*actions)
|
65
|
+
actions.each do |action|
|
66
|
+
action.configure(self).extend(page_references)
|
67
|
+
|
68
|
+
action.execute
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def incorrect_answer(question)
|
75
|
+
Screengem::IncorrectAnswer.new(question)
|
76
|
+
end
|
77
|
+
|
78
|
+
def page_references
|
79
|
+
@page_references ||= Screengem::PageReferences
|
80
|
+
end
|
81
|
+
|
82
|
+
def recollections
|
83
|
+
@recollections ||= ActiveSupport::HashWithIndifferentAccess.new
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "require_all"
|
2
|
+
require "thor"
|
3
|
+
|
4
|
+
module Screengem
|
5
|
+
class CLI < Thor
|
6
|
+
option :root
|
7
|
+
option :config, default: "dampen_configuration.yml"
|
8
|
+
option :questions, default: "questions"
|
9
|
+
option :tasks, default: "tasks"
|
10
|
+
option :quiet, default: false
|
11
|
+
desc "generate", "Create the sample dampening configuration"
|
12
|
+
def generate
|
13
|
+
root = options[:root]
|
14
|
+
|
15
|
+
# Require all questions and tasks for inclusion in the sample configuration.
|
16
|
+
require_all File.join(root, options[:questions])
|
17
|
+
require_all File.join(root, options[:tasks])
|
18
|
+
|
19
|
+
Screengem.configure do |config|
|
20
|
+
config.dampen_configuration_filename = File.join(root, options[:config])
|
21
|
+
end
|
22
|
+
|
23
|
+
sample_filename = Screengem.configuration.dampen_configuration_sample_filename
|
24
|
+
|
25
|
+
puts "Regenerating #{sample_filename} ..." unless options[:quiet]
|
26
|
+
|
27
|
+
sample_configuration = Screengem::DampenConfigurationGenerator.new.generate
|
28
|
+
|
29
|
+
File.write(sample_filename, sample_configuration.to_yaml)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Screengem
|
2
|
+
#
|
3
|
+
# Concern that adds the ability to create actions.
|
4
|
+
#
|
5
|
+
module Actionable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def action
|
9
|
+
@action ||= action_factory
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
#
|
15
|
+
# Choose the specified action factory. Default to the standard action factory.
|
16
|
+
#
|
17
|
+
def action_factory
|
18
|
+
if browser_factory?
|
19
|
+
Screengem::Factories::BrowserActionFactory.instance
|
20
|
+
else
|
21
|
+
Screengem::Factories::StandardActionFactory.instance
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def browser_factory?
|
26
|
+
Screengem.configuration.browser_actions?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Screengem
|
2
|
+
#
|
3
|
+
# Concern that adds ability to configure with an actor instance.
|
4
|
+
#
|
5
|
+
module Configurable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
attr_reader :actor
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure(actor)
|
13
|
+
@actor = actor
|
14
|
+
|
15
|
+
self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Screengem
|
2
|
+
#
|
3
|
+
# Concern for adding dampening to primitives.
|
4
|
+
#
|
5
|
+
module Dampenable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
#
|
10
|
+
# Since most primitives may be dampened.
|
11
|
+
#
|
12
|
+
def supports_dampening?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Specify a primitive subclass with no dampening.
|
18
|
+
#
|
19
|
+
def skip_dampening
|
20
|
+
define_singleton_method(:supports_dampening?) do
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Specify the dampening configuration scope.
|
27
|
+
#
|
28
|
+
def dampen_scope(scope)
|
29
|
+
define_method(:dampening_scope) do
|
30
|
+
scope
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def seconds_to_dampen
|
36
|
+
dampen_configuration.seconds_to_dampen(dampening_scope, self.class.name)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def dampen_configuration
|
42
|
+
Screengem::DampenConfiguration.instance.configuration
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Screengem
|
2
|
+
#
|
3
|
+
# Concern for adding the command pattern.
|
4
|
+
#
|
5
|
+
module Executable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
#
|
9
|
+
# Subclasses must implement an execute method.
|
10
|
+
#
|
11
|
+
def execute
|
12
|
+
raise "You must define an execute method"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Screengem
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
#
|
7
|
+
# Expose the configuration to users of the Screengem gem.
|
8
|
+
#
|
9
|
+
def self.configure
|
10
|
+
self.configuration ||= Screengem::Configuration.new
|
11
|
+
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Configuration for the Screengem gem.
|
17
|
+
#
|
18
|
+
class Configuration
|
19
|
+
# The name of the YAML file that is used to configure dampening.
|
20
|
+
attr_accessor :dampen_configuration_filename
|
21
|
+
|
22
|
+
# The top level key in the YAML file that is used to configure dampening.
|
23
|
+
attr_accessor :dampen_configuration_root
|
24
|
+
|
25
|
+
# A boolean that specifies that dampening is to be applied.
|
26
|
+
attr_accessor :apply_dampening
|
27
|
+
|
28
|
+
# A boolean that specifies that browser actions are created (used by the ActionFactory).
|
29
|
+
attr_accessor :browser_actions
|
30
|
+
|
31
|
+
# A string that namespaces action classes (used by the ActionFactory).
|
32
|
+
attr_accessor :action_scope
|
33
|
+
|
34
|
+
# A string that namespaces questions classes (used by the QuestionFactory).
|
35
|
+
attr_accessor :question_scope
|
36
|
+
|
37
|
+
# A string that namespaces task classes (used by the TaskFactory).
|
38
|
+
attr_accessor :task_scope
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
self.apply_dampening = false
|
42
|
+
self.browser_actions = false
|
43
|
+
|
44
|
+
self.dampen_configuration_root = "default"
|
45
|
+
|
46
|
+
self.action_scope = "Actions"
|
47
|
+
self.question_scope = "Questions"
|
48
|
+
self.task_scope = "Tasks"
|
49
|
+
end
|
50
|
+
|
51
|
+
def apply_dampening?
|
52
|
+
apply_dampening
|
53
|
+
end
|
54
|
+
|
55
|
+
def browser_actions?
|
56
|
+
browser_actions
|
57
|
+
end
|
58
|
+
|
59
|
+
def dampen_configuration_sample_filename
|
60
|
+
"#{dampen_configuration_filename}.sample"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Screengem
|
2
|
+
#
|
3
|
+
# Exposes the question and task sleep intervals as defined in the dampening configuration.
|
4
|
+
#
|
5
|
+
class DampenConfiguration
|
6
|
+
include ::Singleton
|
7
|
+
|
8
|
+
attr_reader :configuration
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@configuration = DampenConfigurationFactory.new.build_configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def dampen_configuration_key(primitive_class_name)
|
15
|
+
primitive_class_name.demodulize.underscore.gsub(/_(question|task)$/, "")
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Knows how to build a dampen configuration.
|
20
|
+
#
|
21
|
+
class DampenConfigurationFactory
|
22
|
+
def build_configuration
|
23
|
+
if dampening_configured?
|
24
|
+
DampenConfiguration::Standard.new(load_configuration)
|
25
|
+
else
|
26
|
+
DampenConfiguration::None.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def dampening_configured?
|
33
|
+
apply_dampening? && configuration_file_exists?
|
34
|
+
end
|
35
|
+
|
36
|
+
def apply_dampening?
|
37
|
+
Screengem.configuration.apply_dampening?
|
38
|
+
end
|
39
|
+
|
40
|
+
def configuration_file_exists?
|
41
|
+
File.exist?(configuration_yaml)
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_configuration
|
45
|
+
YAML.load_file(configuration_yaml)
|
46
|
+
end
|
47
|
+
|
48
|
+
def configuration_yaml
|
49
|
+
Screengem.configuration.dampen_configuration_filename
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Respond by looking up seconds to dampen in the specified settings.
|
55
|
+
#
|
56
|
+
class Standard
|
57
|
+
include Screengem::PrimitiveKey
|
58
|
+
|
59
|
+
attr_reader :settings
|
60
|
+
|
61
|
+
def initialize(settings)
|
62
|
+
@settings = ActiveSupport::HashWithIndifferentAccess.new(settings).fetch(dampen_configuration_root, {})
|
63
|
+
end
|
64
|
+
|
65
|
+
def seconds_to_dampen(primitive_scope, primitive_class_name)
|
66
|
+
settings.dig(primitive_scope, primitive_key(primitive_class_name)).to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def dampen_configuration_root
|
72
|
+
Screengem.configuration.dampen_configuration_root
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Always respond with no dampening.
|
78
|
+
#
|
79
|
+
class None
|
80
|
+
def seconds_to_dampen(_primitive_scope, _class_name)
|
81
|
+
0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|