triggered_job 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +50 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +42 -0
- data/README.md +1 -1
- data/Rakefile +9 -0
- data/bin/rspec +17 -0
- data/lib/triggered_job/base.rb +10 -0
- data/lib/triggered_job/version.rb +3 -0
- data/lib/triggered_job.rb +25 -0
- data/spec/lib/triggered_job/base_spec.rb +45 -0
- data/spec/lib/triggered_job_spec.rb +78 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/support/constant_helpers.rb +11 -0
- data/triggered_job.gemspec +24 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc9e1201d81e4cdc7758f504eb7ffcb95e880a7e
|
4
|
+
data.tar.gz: 18962f87a51fceeaf4a935a0b8ca60217f31b903
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638ac7bf06ecf8f036b3987bdd75037f9a654375a210a21ef85ec92959914d54b77ed5244a6d1531aa48a59795ff0ce6a796ec8316f774d950972fc5322c94cf
|
7
|
+
data.tar.gz: b9efde17de7bcbb37b82890335ec3cb1fc74367616a469ccc8ef1f71b8e67ef28bfa3936966b6bbdc8562c3955f83b427cb299803f0539a395d8f29d04bef8dd
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
triggered_job (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
docile (1.1.5)
|
11
|
+
json (2.0.2)
|
12
|
+
rake (11.3.0)
|
13
|
+
rspec (3.5.0)
|
14
|
+
rspec-core (~> 3.5.0)
|
15
|
+
rspec-expectations (~> 3.5.0)
|
16
|
+
rspec-mocks (~> 3.5.0)
|
17
|
+
rspec-core (3.5.4)
|
18
|
+
rspec-support (~> 3.5.0)
|
19
|
+
rspec-expectations (3.5.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.5.0)
|
22
|
+
rspec-mocks (3.5.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.5.0)
|
25
|
+
rspec-support (3.5.0)
|
26
|
+
simplecov (0.12.0)
|
27
|
+
docile (~> 1.1.0)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov-html (~> 0.10.0)
|
30
|
+
simplecov-html (0.10.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
rake (~> 11.0)
|
37
|
+
rspec (~> 3.5)
|
38
|
+
simplecov (~> 0.12)
|
39
|
+
triggered_job!
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
1.13.5
|
data/README.md
CHANGED
data/Rakefile
ADDED
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module TriggeredJob
|
2
|
+
class Base
|
3
|
+
def self.triggered_by(table: nil, field: nil)
|
4
|
+
raise ArgumentError, ":table argument is required" if table.nil?
|
5
|
+
raise ArgumentError, ":field argument is required" if field.nil?
|
6
|
+
|
7
|
+
TriggeredJob.set_trigger([table, field].join("__"), self)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "triggered_job/base"
|
2
|
+
|
3
|
+
module TriggeredJob
|
4
|
+
@triggered_jobs = {}
|
5
|
+
|
6
|
+
def self.set_trigger(trigger, klass)
|
7
|
+
raise ArgumentError, "trigger cannot be null" if trigger.nil?
|
8
|
+
raise ArgumentError, "klass cannot be null" if klass.nil?
|
9
|
+
raise ArgumentError, "klass must be a Class" unless klass.is_a?(Class)
|
10
|
+
|
11
|
+
if @triggered_jobs.key?(trigger) && !@triggered_jobs[trigger].empty?
|
12
|
+
@triggered_jobs[trigger] << klass.to_s
|
13
|
+
else
|
14
|
+
@triggered_jobs[trigger] = [klass.to_s]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.clear
|
19
|
+
@triggered_jobs = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.triggered_by(trigger)
|
23
|
+
@triggered_jobs[trigger]
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "support/constant_helpers"
|
3
|
+
|
4
|
+
RSpec.describe TriggeredJob::Base do
|
5
|
+
describe ".triggered_by" do
|
6
|
+
context "missing required attributes" do
|
7
|
+
it "raises exception when missing :table" do
|
8
|
+
begin
|
9
|
+
expect {
|
10
|
+
class A < TriggeredJob::Base
|
11
|
+
triggered_by field: "my_field"
|
12
|
+
end
|
13
|
+
}.to raise_error(ArgumentError, /table/)
|
14
|
+
ensure
|
15
|
+
remove_constants :A
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "raises exception when missing :field" do
|
20
|
+
begin
|
21
|
+
expect {
|
22
|
+
class A < TriggeredJob::Base
|
23
|
+
triggered_by table: "my_table"
|
24
|
+
end
|
25
|
+
}.to raise_error(ArgumentError, /field/)
|
26
|
+
ensure
|
27
|
+
remove_constants :A
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "registers table+field trigger with itself" do
|
33
|
+
begin
|
34
|
+
class A < TriggeredJob::Base
|
35
|
+
triggered_by table: "table", field: "field"
|
36
|
+
end
|
37
|
+
|
38
|
+
expect(TriggeredJob.triggered_by("table__field")).to contain_exactly("A")
|
39
|
+
ensure
|
40
|
+
TriggeredJob.clear
|
41
|
+
remove_constants :A
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "support/constant_helpers"
|
3
|
+
|
4
|
+
RSpec.describe TriggeredJob do
|
5
|
+
describe ".clear" do
|
6
|
+
it "clears the stored triggered jobs" do
|
7
|
+
TriggeredJob.set_trigger("alpha", Struct)
|
8
|
+
|
9
|
+
expect(TriggeredJob.triggered_by("alpha")).to contain_exactly("Struct")
|
10
|
+
TriggeredJob.clear
|
11
|
+
|
12
|
+
expect(TriggeredJob.triggered_by("alpha")).to be nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".triggered_by" do
|
17
|
+
it "returns groups of class names by trigger" do
|
18
|
+
begin
|
19
|
+
class A; end
|
20
|
+
class B; end
|
21
|
+
class C; end
|
22
|
+
TriggeredJob.set_trigger("alpha", A)
|
23
|
+
TriggeredJob.set_trigger("alpha", B)
|
24
|
+
TriggeredJob.set_trigger("beta", C)
|
25
|
+
|
26
|
+
expect(TriggeredJob.triggered_by("alpha")).to contain_exactly("A", "B")
|
27
|
+
expect(TriggeredJob.triggered_by("beta")).to contain_exactly("C")
|
28
|
+
ensure
|
29
|
+
TriggeredJob.clear
|
30
|
+
remove_constants :A, :B, :C
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".set_trigger" do
|
36
|
+
context "with both parameters" do
|
37
|
+
it "does not throw an exception" do
|
38
|
+
begin
|
39
|
+
class A; end
|
40
|
+
|
41
|
+
expect { TriggeredJob.set_trigger("alpha", A) }.not_to raise_error
|
42
|
+
ensure
|
43
|
+
TriggeredJob.clear
|
44
|
+
remove_constants :A
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "invalid parameters" do
|
50
|
+
it "throws exception when trigger is nil" do
|
51
|
+
begin
|
52
|
+
class A; end
|
53
|
+
|
54
|
+
expect { TriggeredJob.set_trigger(nil, A ) }.to raise_error(ArgumentError, /[t|T]rigger.*null/)
|
55
|
+
ensure
|
56
|
+
TriggeredJob.clear
|
57
|
+
remove_constants :A
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "throws exception when klass is nil" do
|
62
|
+
begin
|
63
|
+
expect { TriggeredJob.set_trigger("error", nil) }.to raise_error(ArgumentError, /[k|K]lass.*null/)
|
64
|
+
ensure
|
65
|
+
TriggeredJob.clear
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "throws exception when klass is not a class" do
|
70
|
+
begin
|
71
|
+
expect { TriggeredJob.set_trigger("error", "class") }.to raise_error(ArgumentError, /[c|C]lass/)
|
72
|
+
ensure
|
73
|
+
TriggeredJob.clear
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "/spec"
|
4
|
+
end
|
5
|
+
|
6
|
+
require "triggered_job"
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# rspec-expectations config goes here. You can use an alternate
|
10
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
11
|
+
# assertions if you prefer.
|
12
|
+
config.expect_with :rspec do |expectations|
|
13
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
14
|
+
# and `failure_message` of custom matchers include text for helper methods
|
15
|
+
# defined using `chain`, e.g.:
|
16
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
17
|
+
# # => "be bigger than 2 and smaller than 4"
|
18
|
+
# ...rather than:
|
19
|
+
# # => "be bigger than 2"
|
20
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
21
|
+
end
|
22
|
+
|
23
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
24
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
25
|
+
config.mock_with :rspec do |mocks|
|
26
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
27
|
+
# a real object. This is generally recommended, and will default to
|
28
|
+
# `true` in RSpec 4.
|
29
|
+
mocks.verify_partial_doubles = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
33
|
+
# have no way to turn it off -- the option exists only for backwards
|
34
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
35
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
36
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
37
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
38
|
+
|
39
|
+
# The settings below are suggested to provide a good initial experience
|
40
|
+
# with RSpec, but feel free to customize to your heart's content.
|
41
|
+
#
|
42
|
+
# This allows you to limit a spec run to individual examples or groups
|
43
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
44
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
45
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
46
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
47
|
+
config.filter_run_when_matching :focus
|
48
|
+
|
49
|
+
# Allows RSpec to persist some state between runs in order to support
|
50
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
51
|
+
# you configure your source control system to ignore this file.
|
52
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
53
|
+
|
54
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
55
|
+
# recommended. For more details, see:
|
56
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
57
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
58
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
59
|
+
config.disable_monkey_patching!
|
60
|
+
|
61
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
62
|
+
# be too noisy due to issues in dependencies.
|
63
|
+
config.warnings = true
|
64
|
+
|
65
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
66
|
+
# file, and it's useful to allow more verbose output when running an
|
67
|
+
# individual spec file.
|
68
|
+
if config.files_to_run.one?
|
69
|
+
# Use the documentation formatter for detailed output,
|
70
|
+
# unless a formatter has already been configured
|
71
|
+
# (e.g. via a command-line flag).
|
72
|
+
config.default_formatter = 'doc'
|
73
|
+
end
|
74
|
+
|
75
|
+
# Print the 10 slowest examples and example groups at the
|
76
|
+
# end of the spec run, to help surface which specs are running
|
77
|
+
# particularly slow.
|
78
|
+
config.profile_examples = 10
|
79
|
+
|
80
|
+
# Run specs in random order to surface order dependencies. If you find an
|
81
|
+
# order dependency and want to debug it, you can fix the order by providing
|
82
|
+
# the seed, which is printed after each run.
|
83
|
+
# --seed 1234
|
84
|
+
config.order = :random
|
85
|
+
|
86
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
87
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
88
|
+
# test failures related to randomization by passing the same `--seed` value
|
89
|
+
# as the one that triggered the failure.
|
90
|
+
Kernel.srand config.seed
|
91
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ConstantHelpers
|
2
|
+
def remove_constants(*constants)
|
3
|
+
constants.each { |const| Object.send(:remove_const, const) }
|
4
|
+
rescue NameError => e
|
5
|
+
$stderr.puts "Warning from ConstantHelpers::remove_constants:\n\t#{e}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include ConstantHelpers
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "triggered_job/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "triggered_job"
|
7
|
+
s.version = TriggeredJob::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.date = "2016-10-18"
|
10
|
+
s.author = "Daniel Hanson"
|
11
|
+
s.email = "hansondr@gmail.com"
|
12
|
+
s.homepage = "https://github.com/hansondr/triggered_job"
|
13
|
+
s.license = "MIT"
|
14
|
+
s.summary = "Simple framework for trigger-based jobs"
|
15
|
+
s.description = "Simple framework for trigger-based jobs"
|
16
|
+
|
17
|
+
s.add_development_dependency "rspec", "~> 3.5"
|
18
|
+
s.add_development_dependency "simplecov", "~> 0.12"
|
19
|
+
s.add_development_dependency "rake", "~> 11.0"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triggered_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Hanson
|
@@ -58,8 +58,22 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ".rspec"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
61
65
|
- LICENSE
|
62
66
|
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/rspec
|
69
|
+
- lib/triggered_job.rb
|
70
|
+
- lib/triggered_job/base.rb
|
71
|
+
- lib/triggered_job/version.rb
|
72
|
+
- spec/lib/triggered_job/base_spec.rb
|
73
|
+
- spec/lib/triggered_job_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/support/constant_helpers.rb
|
76
|
+
- triggered_job.gemspec
|
63
77
|
homepage: https://github.com/hansondr/triggered_job
|
64
78
|
licenses:
|
65
79
|
- MIT
|
@@ -84,4 +98,8 @@ rubygems_version: 2.5.1
|
|
84
98
|
signing_key:
|
85
99
|
specification_version: 4
|
86
100
|
summary: Simple framework for trigger-based jobs
|
87
|
-
test_files:
|
101
|
+
test_files:
|
102
|
+
- spec/lib/triggered_job/base_spec.rb
|
103
|
+
- spec/lib/triggered_job_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/support/constant_helpers.rb
|