laters 0.1.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: c6ad4e042b43cac1765ea61b494fc1ec86ebe4fcfb68c888be4e2a7fdded4985
4
+ data.tar.gz: 86b3ffe9dab1b85dc2ca73dac4417d3a8b71d25aadda551927e32d4389784a64
5
+ SHA512:
6
+ metadata.gz: ce904311b5114eef4e8c7b4d2569a49c46ca17e184a570ae3829eda0a7f508b850fba966307d8de583eecb253e683a3280aee9ebfe793b90ee67d9d58085199e
7
+ data.tar.gz: 2c8d9566b52771b4494bc01736f5db1e677d68a5ff36798534d18440ee0e9245c5bd8380ac6b8dcb73916523382b7de4c66e7e7e311384e235308b808d5a0073
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # 0.1.1 (23-8-2020)
2
+
3
+ - Rename gem to `laters`
4
+
5
+ # 0.1.0 (23-8-2020)
6
+
7
+ - Initial version
@@ -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 kieranklaassen@gmail.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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Kieran Klaassen
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,77 @@
1
+ # Laters
2
+
3
+ Run any instance_method of ActiveRecord models via a job by adding `_later` to it. Laters 👋, means See you later in
4
+ Dutch 🇳🇱
5
+
6
+ ## Installation
7
+
8
+ Add to your Gemfile
9
+
10
+ $ bundle add laters
11
+
12
+ Or install it yourself as:
13
+
14
+ $ gem install laters
15
+
16
+ ## Usage
17
+
18
+ 1. Include the `Laters::Concern` in your model
19
+ 2. Call instance methods with `_later`
20
+
21
+ ```rb
22
+ class User < ApplicationRecord
23
+ include Laters::Concern
24
+
25
+ after_create_commit :notify_user_later
26
+ after_commit :refresh_cache_later
27
+
28
+ private
29
+
30
+ def notify_user
31
+ # External services
32
+ Sms.send(to: user.phone, message: 'Hey!')
33
+ end
34
+
35
+ def refresh_cache!
36
+ # Expensive calculation
37
+ end
38
+ end
39
+ ```
40
+
41
+ To set the queue to any other than the `default` set it like this:
42
+
43
+ ```rb
44
+ class User < ApplicationRecord
45
+ include Laters::Concern
46
+
47
+ run_in_queue :low
48
+ end
49
+ ```
50
+
51
+ If you need callbacks, they are provided as standart model callbacks:
52
+
53
+ ```rb
54
+ class User < ApplicationRecord
55
+ include Laters::Concern
56
+
57
+ before_laters :do_something
58
+ after_laters :do_something_more
59
+ around_laters :do_something_around
60
+ # Etc..
61
+ end
62
+ ```
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kieranklaassen/laters. This project is
67
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
68
+ [code of conduct](https://github.com/kieranklaassen/laters/blob/master/CODE_OF_CONDUCT.md).
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the Laters project's codebases, issue trackers, chat rooms and mailing lists is expected to
77
+ follow the [code of conduct](https://github.com/kieranklaassen/laters/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Laters
4
+ class InstanceMethodJob < ActiveJob::Base
5
+ def perform(object, method_name, *args)
6
+ if object.respond_to? :id
7
+ Rails.logger.info "Calling deferred #{method_name} on #{object.class} ##{object.id}"
8
+ else
9
+ Rails.logger.info "Calling deferred #{object.class}##{method_name}"
10
+ end
11
+
12
+ object.run_callbacks(:laters) { object.send(method_name, *args) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Laters
4
+ module Concern
5
+ extend ActiveSupport::Concern
6
+ include ActiveModel::Callbacks
7
+
8
+ included { define_model_callbacks :laters }
9
+
10
+ class_methods do
11
+ attr_reader :job_queue
12
+
13
+ private
14
+
15
+ def run_in_queue(queue)
16
+ @job_queue = queue
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def method_missing(method, *args, &block)
23
+ if (method_to_call = deferrable_method_name(method))
24
+ InstanceMethodJob
25
+ .set(queue: self.class.job_queue || :default)
26
+ .perform_later(self, method_to_call, *args)
27
+ else
28
+ super
29
+ end
30
+ end
31
+
32
+ def respond_to_missing?(method_name, include_private = false)
33
+ method_name.to_s.ends_with?('_later') || super
34
+ end
35
+
36
+ # @param [Symbol] deferring_method Name of the deferring method that was called
37
+ def deferrable_method_name(deferring_method)
38
+ return unless (method = deferring_method.to_s).ends_with? '_later'
39
+
40
+ method.chomp! '_later'
41
+ if respond_to? "#{method}!", true
42
+ "#{method}!"
43
+ elsif respond_to? method, true
44
+ method
45
+ end
46
+ end
47
+ end
48
+ end
data/lib/laters.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'laters/version'
2
+ require 'active_model'
3
+ require 'active_job'
4
+ require 'zeitwerk'
5
+ loader = Zeitwerk::Loader.for_gem
6
+ loader.push_dir('app/models/concerns')
7
+ loader.push_dir('app/jobs')
8
+ loader.setup
9
+
10
+ module Laters
11
+ class Error < StandardError; end
12
+ end
13
+
14
+ loader.eager_load
@@ -0,0 +1,3 @@
1
+ module Laters
2
+ VERSION = '0.1.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: laters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kieran Klaassen
8
+ - Pelle ten Cate
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '4.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '4.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: zeitwerk
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Deferrable empowers a class to run every single defined method wrapped
43
+ in an ActiveJob of any class that includes it
44
+ email:
45
+ - kieranklaassen@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - app/jobs/laters/instance_method_job.rb
56
+ - app/models/concerns/laters/concern.rb
57
+ - lib/laters.rb
58
+ - lib/laters/version.rb
59
+ homepage: https://github.com/kieranklaassen/laters
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://github.com/kieranklaassen/laters
64
+ source_code_uri: https://github.com/kieranklaassen/laters
65
+ changelog_uri: https://github.com/kieranklaassen/laters/blob/master/CHANGELOG.md
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.3.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.1.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Run any instance_method in ActiveRecord models via a job by adding `_later`
85
+ to it.
86
+ test_files: []