active_model-jobs 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3498758a1e49f162cf4ac307c59fcc514f84cf4b
4
- data.tar.gz: d6cfb41f2ea4efa81fd306bafd2f7e0bf48feac1
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTUzOTg4NGI1ZGRmNTU4OTk4ZmM5YmU0NmQ2YjM2ZDY3NjUzOGQyNg==
5
+ data.tar.gz: !binary |-
6
+ MmQ4ZWRiYTg3OTlhZWZlZGY4YzlmMTU2Mzc4Y2YxMTdlZDQyMWZkMA==
5
7
  SHA512:
6
- metadata.gz: 56cf8488a7d852d7f226bf97a9213e7fa783611bb5b6b1473f11e5da8fe609dff8bbb6016c88146477b639f5ded2a65e2a060eb6363e7ca764acaf2c53da4dea
7
- data.tar.gz: 6c7d2fc095551477b5f815b1569b43e20d9faf8370e948d8501b4efe17f92b3b2082d5cba94ac4bc5a3017e42a46e0ba01bbdace7231ace9d3cae21264ef1289
8
+ metadata.gz: !binary |-
9
+ MmEzOTJmNjg1YWMwMjBkYjAxNjAzYTBkYmJmMzJmZTI4NGQ4YWU0Y2U2NGMx
10
+ M2NkMjI1NTg3ZGI5ODFjN2JiMjk1MDc1ZjViMTFlNjU5YjYwMTdkYTZiMTY2
11
+ NmE1OGJkNDBlYWFjZmU0NDBmNDgzMDNjNmQ2OTAxMzI1MzI5YWM=
12
+ data.tar.gz: !binary |-
13
+ YmNiZGIyOWM3MzI3OTYzNWJmYjIyY2E2NzM3NTU5NzE5Njk0NjM5ZTdjYmU0
14
+ NzljNTIyNGNiMGE1NWNkMGFmYjI3ZGYxMmUyNDkzYjE2NmEzNjNkN2ZkNTY0
15
+ MDRmMjdkMDFmOWViMjczZWIyZjFhODA3ZDVlMjkzMDEyZGRmMzM=
data/.bundle/config ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ BUNDLE_BIN: "./bin"
3
+ BUNDLE_RETRY: 3
4
+ BUNDLE_JOBS: 3
data/.travis.yml CHANGED
@@ -1,5 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.2.2
4
4
  deploy:
5
- # TODO: to rubygems
5
+ provider: rubygems
6
+ api_key:
7
+ secure: JQWmjd5/4zPBjt33e+ZF5+lmz7nsek6X6Q5Er06q/Qbaeak/uxCd/7hW8mP6mesh6p/OOBIYlRBOxN/GHf7/TWd+n5LrmCye18iyqGQlgwrB3ULoDqSh/GBBLp4u4zI6oBZJA3GoC5mDyDg5Mdf5ye0yVBhbfT3D9+VUyq53xrKI3B3pKztTgvZ/KzF4Gsb3UrN5R0E9Q4NZLrkIlApM517BXKnDTpk1DYZGe12FYZtgZMCkSPtiohZ5qizHDq6HK8ZgPPZ970QEu1jIFUs4luF0qKOCYhO9Yq9UWL1m+eRwa/s/j8Vyww9dPg2x9yReDWcIf0gZMKPBMgVQrnfT/YER5L0cee2XbxI6LdPwkvrx7EQwb5e2z/bzVr7IuiZrewWUTNaO7v9NnKSnS3smfbtu9gK5AYzf0X1z42vWCnCwJNYGAJd2sD1dw80zBtWf0YlonrRnXTUTdapSV3FAZBLFNHL9YNldZ9bjT3cPLhZv/ajk9eL7wOWGVRzghfUTYkTdIGQtH1nasVj99b9cuENj8HEJbnh7r8CgkpyuyZ5YjyZt+VCwCxeImPYv7uJbUlChFipdhC5NTvfIkcsDuXWWP+Va67MTchCnf+chCFD4oRLKuc9atkpSdawpvQ4T5tYiqa5nhscLm79bE2Md/VYqdgWo+JzbPOHq4MqAg4Q=
8
+ gem: active_model-jobs
9
+ on:
10
+ tags: true
11
+ repo: tubbo/active_model-jobs
data/README.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # ActiveModel::Jobs
2
2
 
3
+ [![Build Status](https://travis-ci.org/tubbo/active_model-jobs.svg)](https://travis-ci.org/tubbo/active_model-jobs)
4
+ [![Code Climate](https://codeclimate.com/github/tubbo/active_model-jobs/badges/gpa.svg)](https://codeclimate.com/github/tubbo/active_model-jobs)
5
+ [![Test Coverage](https://codeclimate.com/github/tubbo/active_model-jobs/badges/coverage.svg)](https://codeclimate.com/github/tubbo/active_model-jobs/coverage)
6
+ [![Inline docs](http://inch-ci.org/github/tubbo/active_model-jobs.svg?branch=master)](http://inch-ci.org/github/tubbo/active_model-jobs)
7
+
3
8
  A model-level interface for kicking off background jobs using ActiveJob.
9
+ Most useful inside a Rails application, it enables you to enqueue
10
+ ActiveJob jobs with a dynamically-generated instance method inside your
11
+ ActiveRecord (or ActiveModel-compatible) model class.
12
+
13
+ [Documentation](http://www.rubydoc.info/github/tubbo/active_model-jobs/master)
4
14
 
5
15
  ## Installation
6
16
 
@@ -44,28 +54,24 @@ model:
44
54
 
45
55
  ```ruby
46
56
  class Track < ActiveRecord::Base
47
- include ActiveModel::Jobs
57
+ attachment :file
48
58
 
49
- after_commit :upload!, on: :create
59
+ after_create :upload!
50
60
  end
51
61
  ```
52
62
 
53
63
  Since this is just an instance method, you can call `track.upload!` to
54
64
  kick off the job at any time outside of the callback lifecycle.
55
65
 
56
- ### Global Inclusion
57
-
58
- You can include this module in every ActiveRecord model by inserting the
59
- following code into an initializer at
60
- **config/initializers/active_model_jobs.rb**:
61
-
62
- ```ruby
63
- ActiveRecord::Base.send :include, ActiveModel::Jobs
64
- ```
65
-
66
66
  ## Development
67
67
 
68
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
68
+ After checking out the repo, run `bin/setup` to install dependencies.
69
+ Then, run `bin/console` for an interactive prompt that will allow you
70
+ to experiment.
71
+
72
+ We follow a [semantic versioning](http://semver.org) guideline when
73
+ releasing new versions. Documentation updates do not get a new version,
74
+ it is just merged into 'master' and updated on http://rubydoc.info.
69
75
 
70
76
  ## Contributing
71
77
 
data/Rakefile CHANGED
@@ -8,9 +8,10 @@ RSpec::Core::RakeTask.new :spec
8
8
 
9
9
  RuboCop::RakeTask.new :lint
10
10
 
11
- YARD::Rake::YardocTask.new :docs
11
+ YARD::Rake::YardocTask.new :doc
12
12
 
13
13
  desc "Run all RuboCop lint checks and RSpec code examples"
14
14
  task test: %w(lint spec)
15
15
 
16
- task default: %i(test build docs release)
16
+ # CI task.
17
+ task default: :test
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "yard"
32
32
 
33
33
  spec.add_dependency "activemodel"
34
+ spec.add_dependency "activejob"
34
35
  end
data/bin/setup CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
+
2
3
  set -euo pipefail
3
4
  IFS=$'\n\t'
4
5
 
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
6
+ bundle check || bundle install
7
+ ./bin/rake doc
@@ -0,0 +1,16 @@
1
+ if defined? Rails
2
+ module ActiveModel
3
+ module Jobs
4
+ # Hooks into the host Rails application that include
5
+ # +ActiveModel::Jobs+ into every model that includes
6
+ # +ActiveModel::Model+.
7
+ class Engine < Rails::Engine
8
+ initializer 'active_model_jobs.setup' do
9
+ ActiveSupport.on_load :active_model do
10
+ ActiveModel::Model.send :include, ActiveModel::Jobs
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -5,31 +5,40 @@ module ActiveModel
5
5
  # to a given action method on a given model. When the job class is
6
6
  # found, the action method fires off a new instance of the job.
7
7
  #
8
- # @api private
9
8
  # @private
10
9
  class Performer
11
- # @type [RegExp]
10
+ # Regular expression for finding a '!' at the end of a String.
12
11
  BANG = /!\Z/
13
12
 
14
- # @attr_reader
15
- # @type [String]
13
+ # The method name given to the class as a String.
14
+ #
15
+ # @attr_reader [String]
16
16
  attr_reader :method_name
17
17
 
18
- # @attr_reader
19
- # @type [String]
18
+ # The model name given to the class by +ActiveModel::Naming+.
19
+ #
20
+ # @attr_reader [String]
21
+ # @see http://api.rubyonrails.org/classes/ActiveModel/Naming.html
20
22
  attr_reader :model_name
21
23
 
22
- # @param [String] method_name - A method corresponding to a job.
23
- # @param [String] model_name - The model we are calling this from.
24
+ # @param [String] method_name A method corresponding to a job.
25
+ # @param [String] model_name The model we are calling this from.
24
26
  def initialize(method_name, model_name)
25
27
  @method_name = method_name.to_s
26
28
  @model_name = model_name.to_s
27
29
  end
28
30
 
31
+ # Tests whether the given method name ends with a '!'.
32
+ #
33
+ # @return [Boolean]
34
+ def self.action?(method)
35
+ method =~ BANG
36
+ end
37
+
29
38
  # Tests whether this method name corresponds to a job class in the
30
39
  # application.
31
40
  #
32
- # @returns [Boolean] whether this job exists or not
41
+ # @return [Boolean] whether this job exists or not
33
42
  def job?
34
43
  method_name =~ BANG && job_class.present?
35
44
  end
@@ -37,7 +46,7 @@ module ActiveModel
37
46
  # Attempts to find the job class for this method and return it,
38
47
  # otherwise it returns +nil+ when encountering a +NameError+.
39
48
  #
40
- # @returns [ActiveJob::Base] a job class or nil
49
+ # @return [ActiveJob::Base] a job class or nil
41
50
  def job_class
42
51
  job_name.classify.constantize
43
52
  rescue NameError
@@ -47,24 +56,24 @@ module ActiveModel
47
56
  # Build the conventional job name from the given method and model.
48
57
  # Suffix with +job+ and separate with underscores.
49
58
  #
50
- # @returns [String] the underscored job class name
59
+ # @return [String] the underscored job class name
51
60
  def job_name
52
- [
53
- action_name, model_name, 'job'
54
- ].join '_'
61
+ "#{action_name}_#{model_name}_job"
55
62
  end
56
63
 
57
64
  # Strip the '!' off of the end of the method.
58
65
  #
59
- # @returns [String]
66
+ # @return [String] '!'-stripped version of the method name.
60
67
  def action_name
61
68
  method_name.gsub BANG, ''
62
69
  end
63
70
 
64
71
  # Perform this action on the given model.
65
72
  #
66
- # @param [ActiveModel::Model]
67
- # @returns [TrueClass]
73
+ # @param [ActiveModel::Model] model The model object we are
74
+ # performing the job on
75
+ # @return [TrueClass, FalseClass] whether the job succeeded to
76
+ # enqueue.
68
77
  def call(model)
69
78
  return false unless job?
70
79
  job_class.perform_later model
@@ -1,7 +1,7 @@
1
- # :nodoc:
1
+ # @see http://api.rubyonrails.org/classes/ActiveModel/Model.html
2
2
  module ActiveModel
3
3
  module Jobs
4
4
  # @type [String]
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -2,13 +2,20 @@ require "active_support/all"
2
2
  require "active_model"
3
3
  require "active_model/jobs/version"
4
4
  require "active_model/jobs/performer"
5
+ require "active_model/jobs/engine"
5
6
 
7
+ # :nodoc:
6
8
  module ActiveModel
7
9
  # Include this module into your model to take advantage of
8
- # automatically-generated :#{job_name}! action methods for any
10
+ # automatically-generated +:job_name!+ action methods for any
9
11
  # matching ActiveJob classes.
10
12
  #
11
- # @api public
13
+ # @example
14
+ # class MyModel < ActiveRecord::Base
15
+ # include ActiveModel::Jobs
16
+ #
17
+ # after_commit :deploy!
18
+ # end
12
19
  module Jobs
13
20
  # Call +perform_later+ on an ActiveJob class corresponding to an
14
21
  # undefined action method name. Most of the work here is done in the
@@ -22,14 +29,14 @@ module ActiveModel
22
29
  # @throws NoMethodError if no job matches the action method
23
30
  def method_missing(method, *arguments)
24
31
  performer = job_performer(method)
25
- return super unless performer.present?
32
+ return super unless performer.present? && performer.job?
26
33
  performer.call self
27
34
  end
28
35
 
29
36
  private
30
37
 
31
38
  def job_performer(method)
32
- return unless method =~ Performer::BANG
39
+ return unless Performer.action? method
33
40
  Performer.new method, model_name
34
41
  end
35
42
  end
metadata CHANGED
@@ -1,97 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Scott
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-11 00:00:00.000000000 Z
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activemodel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activejob
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  description: Helper module for initiating ActiveJobs through an ActiveRecord model.
@@ -101,12 +115,13 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - ".env"
105
- - ".gitignore"
106
- - ".rspec"
107
- - ".rubocop.yml"
108
- - ".ruby-version"
109
- - ".travis.yml"
118
+ - .bundle/config
119
+ - .env
120
+ - .gitignore
121
+ - .rspec
122
+ - .rubocop.yml
123
+ - .ruby-version
124
+ - .travis.yml
110
125
  - CODE_OF_CONDUCT.md
111
126
  - Gemfile
112
127
  - LICENSE.txt
@@ -126,6 +141,7 @@ files:
126
141
  - bin/yardoc
127
142
  - bin/yri
128
143
  - lib/active_model/jobs.rb
144
+ - lib/active_model/jobs/engine.rb
129
145
  - lib/active_model/jobs/performer.rb
130
146
  - lib/active_model/jobs/version.rb
131
147
  homepage: http://github.com/tubbo/active_model-jobs
@@ -138,12 +154,12 @@ require_paths:
138
154
  - lib
139
155
  required_ruby_version: !ruby/object:Gem::Requirement
140
156
  requirements:
141
- - - ">="
157
+ - - ! '>='
142
158
  - !ruby/object:Gem::Version
143
159
  version: '0'
144
160
  required_rubygems_version: !ruby/object:Gem::Requirement
145
161
  requirements:
146
- - - ">="
162
+ - - ! '>='
147
163
  - !ruby/object:Gem::Version
148
164
  version: '0'
149
165
  requirements: []
@@ -153,4 +169,3 @@ signing_key:
153
169
  specification_version: 4
154
170
  summary: Helper module for initiating ActiveJobs through an ActiveRecord model.
155
171
  test_files: []
156
- has_rdoc: