rails-active_action 3.0.1 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff2e75a715d3b2d1b53ee9d56fc6a8cebcaacd266118a5b5b8815d5477f9c4cc
4
- data.tar.gz: 3a8f83660ee46305ae67067812de458f4f871ecee67621d158185b8deb6c27aa
3
+ metadata.gz: 3a12631690e2211e38f6d66f01977210f6ba14591663a06bc78ef512e5f4dc70
4
+ data.tar.gz: 109c7104bc600fa610fd137bd34fc9f587882fcb65c8c65c9c7750e136643293
5
5
  SHA512:
6
- metadata.gz: d3b7b4840cad4c038c7251de599338d500ce4d920439260f960c2159805f1750fe2f6d5f713e0bbd42b9aefe4b17c8cfb9be44ed7669219391a71a0e14417c20
7
- data.tar.gz: 6911724f30328d0a8b14edf489bdfcf9ae39f9cab93204b5f162ab896c304244f4c432e81aa0d02ae2d240861baf05a40816102c072b7fe2abb3f8b83afacba9
6
+ metadata.gz: e803bf8e6d91d92786d649daad700d3e2f2708710a01371c07cb87e9617e1d62e27abda9b47191cbafa90690398d7e0e6448b6f35689c56ae3c97ce8f6d5d2fe
7
+ data.tar.gz: 19374304e7407bb3ccd2ca32ee3ba99a27c45b7a3088a3128b5c49a18c90760967e68970695dccd335439f617ebf32bbd7d81b6341fd513e5aae9ad43313caec
data/Gemfile CHANGED
@@ -1,11 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gemspec
4
-
5
- gem 'activesupport', '>= 3.0.1'
6
-
7
- group :test do
8
- gem 'rake', '~> 12.0'
9
- gem 'rspec', '~> 3.0'
10
- gem 'i18n', '~> 1.8.9'
11
- end
3
+ gem 'ruby-active_action', '~> 3.0.1'
data/Gemfile.lock CHANGED
@@ -1,40 +1,13 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rails-active_action (3.0.1)
5
-
6
1
  GEM
7
2
  remote: https://rubygems.org/
8
3
  specs:
9
- activesupport (3.0.20)
10
- concurrent-ruby (1.1.8)
11
- diff-lcs (1.4.4)
12
- i18n (1.8.9)
13
- concurrent-ruby (~> 1.0)
14
- rake (12.3.3)
15
- rspec (3.10.0)
16
- rspec-core (~> 3.10.0)
17
- rspec-expectations (~> 3.10.0)
18
- rspec-mocks (~> 3.10.0)
19
- rspec-core (3.10.1)
20
- rspec-support (~> 3.10.0)
21
- rspec-expectations (3.10.1)
22
- diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.10.0)
24
- rspec-mocks (3.10.2)
25
- diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.10.0)
27
- rspec-support (3.10.2)
4
+ ruby-active_action (3.0.1)
28
5
 
29
6
  PLATFORMS
30
7
  ruby
31
8
 
32
9
  DEPENDENCIES
33
- activesupport (>= 3.0.1)
34
- i18n (~> 1.8.9)
35
- rails-active_action!
36
- rake (~> 12.0)
37
- rspec (~> 3.0)
10
+ ruby-active_action (~> 3.0.1)
38
11
 
39
12
  BUNDLED WITH
40
13
  2.1.4
data/README.md CHANGED
@@ -1,172 +1,49 @@
1
- # ActiveAction
2
-
3
- A simple way to build and use Service Objects in Ruby on Rails.
4
1
 
5
- ## Installation
2
+ [![Gem Version](https://badge.fury.io/rb/rails-active_action.svg)](https://badge.fury.io/rb/rails-active_action)
3
+ [![License MIT](https://img.shields.io/github/license/lukaszsliwa/rails-active_action)](https://github.com/lukaszsliwa/rails-active_action/blob/main/LICENSE)
4
+ [![GitHub issues](https://img.shields.io/github/issues/lukaszsliwa/rails-active_action)](https://github.com/lukaszsliwa/rails-active_action/issues)
6
5
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'rails-active_action', '~> 3.0.0'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle install
6
+ # ActiveAction
16
7
 
17
- Or install it yourself as:
8
+ A simple way to build and use Service Objects.
18
9
 
19
- $ gem install rails-active_action
10
+ Visit the parent [ruby-active_action](https://github.com/lukaszsliwa/active_action) gem.
20
11
 
21
- ## ActiveAction example
22
12
 
23
- ```ruby
24
- # app/actions/my_action.rb
25
- class MyAction < ActiveAction::Base
26
- def perform
27
- # Your code here
28
- end
29
- end
30
-
31
- # app/controllers/my_controller.rb
32
- class MyController < ApplicationController
33
- def create
34
- MyAction.perform
35
- end
36
- end
37
- ```
13
+ ## Installation
38
14
 
39
- or `perform!` to raise an error if occurred.
15
+ Add this line to your application's Gemfile:
40
16
 
41
17
  ```ruby
42
- # app/actions/my_action.rb
43
- class MyAction < ActiveAction::Base
44
- def perform
45
- # Your code here
46
- error!
47
- end
48
- end
49
-
50
- # app/controllers/my_controller.rb
51
- class MyController < ApplicationController
52
- def create
53
- MyAction.perform! # it will raise ActiveAction::Error
54
- end
55
- end
18
+ gem 'rails-active_action', '~> 3.0.7'
56
19
  ```
57
20
 
58
- ## Demo
21
+ or use original gem:
59
22
 
60
23
  ```ruby
61
- # app/actions/create_user_action.rb
62
- class CreateUser < ActiveAction::Base
63
- attributes :user
64
-
65
- after_perform :send_email_on_success, on: :success
66
-
67
- def perform(company, params)
68
- self.user = company.users.build(params)
69
- if self.user.save
70
- success!
71
- else
72
- error!
73
- end
74
- end
75
-
76
- def send_email_on_success
77
- User.welcome.with(user: self.user).deliver
78
- end
79
- end
80
-
81
- # app/controllers/users_controller.rb
82
- class UsersController < ApplicationController
83
- def create
84
- context = CreateUser.perform(current_company, params_user)
85
-
86
- respond_to do |format|
87
- if context.success?
88
- format.html { redirect_to dashboard_path, notice: 'Welcome to our app' }
89
- else
90
- format.html { render action: :new }
91
- end
92
- end
93
- end
94
-
95
- private
96
-
97
- def current_company
98
- @company ||= Company.find_by!(subdomain: request.subdomain)
99
- end
100
- end
24
+ gem 'ruby-active_action', '~> 3.0.7'
101
25
  ```
102
26
 
103
- ## Callbacks
27
+ or use alternative gems:
104
28
 
105
- On `success` or `error`:
106
- * `after_perform`
107
- * `before_perform`
108
-
109
- ```ruby
110
- # app/actions/create_post.rb
111
- class CreatePost < ActiveAction::Base
112
- before_perform do
113
- # run a code before perform within a block
114
- end
115
-
116
- after_perform do
117
- # run a code after perform within a block
118
- end
119
-
120
- after_perform :run_callback, on: :success
121
- after_perform :run_warning_email, on: :error
122
-
123
- def perform(user, params: {})
124
- # your code here
125
- end
126
- end
127
- ```
29
+ * [rails-active_action](https://github.com/lukaszsliwa/rails-active_action)
30
+ * [cuba-active_action](https://github.com/lukaszsliwa/cuba-active_action)
31
+ * [grape-active_action](https://github.com/lukaszsliwa/grape-active_action)
32
+ * [hanami-active_action](https://github.com/lukaszsliwa/hanami-active_action)
33
+ * [nyny-active_action](https://github.com/lukaszsliwa/nyny-active_action)
34
+ * [padrino-active_action](https://github.com/lukaszsliwa/padrino-active_action)
35
+ * [ramaze-active_action](https://github.com/lukaszsliwa/ramaze-active_action)
36
+ * [roda-active_action](https://github.com/lukaszsliwa/roda-active_action)
37
+ * [sinatra-active_action](https://github.com/lukaszsliwa/sinatra-active_action)
128
38
 
129
- * `around_perform`
39
+ And then execute:
130
40
 
131
- ```ruby
132
- # app/actions/run_process.rb
133
- class RunProcess < ActiveAction::Base
134
- around_perform :measure
135
-
136
- def measure
137
- @start = Time.current
138
- yield
139
- @end = Time.current
140
- end
141
-
142
- def perform(id)
143
- `#{Process.find(id).command}`
144
- end
145
- end
146
- ```
41
+ $ bundle install
147
42
 
148
- ## Statuses
43
+ ## ActiveAction example
149
44
 
150
- Call `success!`, `succeed!`, `done!`, `correct!`, `ready!`, `active!` if the action performed successfully or `error!`, `fail!`, `failure!`, `failed!`, `invalid!`, `incorrect!`, `inactive!` otherwise.
45
+ Visit [ruby-active_action](https://github.com/lukaszsliwa/active_action) gem for examples.
151
46
 
152
- ```ruby
153
- # app/actions/run.rb
154
- class Run < ActiveAction::Base
155
- def perform
156
- if rand(100) % 2 == 0
157
- success!
158
- else
159
- fail!
160
- end
161
- end
162
-
163
- after_perform :send_email_on_success
164
-
165
- def send_email_on_success
166
- Mail.deliver! if success?
167
- end
168
- end
169
- ```
170
47
 
171
48
  ## Contributing
172
49
 
data/Rakefile CHANGED
@@ -1,6 +1 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,19 +1,17 @@
1
- require_relative 'lib/active_action/version'
2
-
3
1
  Gem::Specification.new do |spec|
4
2
  spec.name = "rails-active_action"
5
- spec.version = ActiveAction::VERSION
3
+ spec.version = '3.0.7'
6
4
  spec.authors = ["Łukasz Śliwa"]
7
5
  spec.email = ["lukasz.sliwa@apptamers.com"]
8
6
 
9
- spec.summary = %q{A simple way to build and use Service Objects in Ruby on Rails.}
7
+ spec.summary = %q{A simple way to build and use Service Objects.}
10
8
  spec.description = %q{ActiveAction makes you able to organise and move some actions to the separated classes.}
11
- spec.homepage = "https://github.com/lukaszsliwa/active_action"
9
+ spec.homepage = "https://github.com/lukaszsliwa/rails-active_action"
12
10
  spec.license = "MIT"
13
11
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
12
 
15
13
  spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = "https://github.com/lukaszsliwa/active_action"
14
+ spec.metadata["source_code_uri"] = "https://github.com/lukaszsliwa/rails-active_action"
17
15
 
18
16
  # Specify which files should be added to the gem when it is released.
19
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-active_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Łukasz Śliwa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-28 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ActiveAction makes you able to organise and move some actions to the
14
14
  separated classes.
@@ -28,21 +28,13 @@ files:
28
28
  - LICENSE.txt
29
29
  - README.md
30
30
  - Rakefile
31
- - bin/console
32
- - bin/setup
33
- - lib/active_action.rb
34
- - lib/active_action/base.rb
35
- - lib/active_action/callbacks.rb
36
- - lib/active_action/error.rb
37
- - lib/active_action/statuses.rb
38
- - lib/active_action/version.rb
39
31
  - rails-active_action.gemspec
40
- homepage: https://github.com/lukaszsliwa/active_action
32
+ homepage: https://github.com/lukaszsliwa/rails-active_action
41
33
  licenses:
42
34
  - MIT
43
35
  metadata:
44
- homepage_uri: https://github.com/lukaszsliwa/active_action
45
- source_code_uri: https://github.com/lukaszsliwa/active_action
36
+ homepage_uri: https://github.com/lukaszsliwa/rails-active_action
37
+ source_code_uri: https://github.com/lukaszsliwa/rails-active_action
46
38
  post_install_message:
47
39
  rdoc_options: []
48
40
  require_paths:
@@ -61,5 +53,5 @@ requirements: []
61
53
  rubygems_version: 3.1.2
62
54
  signing_key:
63
55
  specification_version: 4
64
- summary: A simple way to build and use Service Objects in Ruby on Rails.
56
+ summary: A simple way to build and use Service Objects.
65
57
  test_files: []
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "active_action"
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/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/active_action.rb DELETED
@@ -1,31 +0,0 @@
1
- require 'active_support/dependencies/autoload'
2
- require 'active_support/callbacks'
3
-
4
- require 'active_action/version'
5
- require 'active_action/statuses'
6
- require 'active_action/callbacks'
7
- require 'active_action/base'
8
- require 'active_action/error'
9
-
10
- #
11
- # Examples
12
- #
13
- # class MyAction < ActiveAction::Base
14
- # after_perform :send_email, on: :success
15
- #
16
- # def perform(email_address)
17
- #
18
- # end
19
- #
20
- # def send_email
21
- #
22
- # end
23
- # end
24
- #
25
-
26
- module ActiveAction
27
- extend ActiveSupport::Autoload
28
-
29
- autoload :Base
30
- autoload :Error
31
- end
@@ -1,36 +0,0 @@
1
- module ActiveAction
2
- class Base
3
- include ActiveSupport::Callbacks
4
- define_callbacks :perform
5
-
6
- extend ActiveAction::Callbacks
7
- include ActiveAction::Statuses
8
-
9
- attr_reader :status
10
- attr_accessor :value
11
-
12
- class << self
13
- alias_method :attributes, :attr_accessor
14
-
15
- def perform(*args)
16
- instance = self.new
17
- instance.value = instance.send(:perform_with_callbacks, *args)
18
- instance.success! if instance.status.nil?
19
- instance
20
- end
21
-
22
- def perform!(*args)
23
- if (instance = perform(*args)).error?
24
- raise ActiveAction::Error.new
25
- end
26
- instance
27
- end
28
- end
29
-
30
- def perform_with_callbacks(*args)
31
- run_callbacks :perform do
32
- perform(*args)
33
- end
34
- end
35
- end
36
- end
@@ -1,26 +0,0 @@
1
- module ActiveAction
2
- module Callbacks
3
- def after_perform(method_name = nil, params = {}, &block)
4
- prepare_callback(:perform, :after, method_name, params, &block)
5
- end
6
-
7
- def before_perform(method_name = nil, params = {}, &block)
8
- prepare_callback(:perform, :before, method_name, params, &block)
9
- end
10
-
11
- def around_perform(method_name)
12
- set_callback(:perform, :around, method_name)
13
- end
14
-
15
- private
16
-
17
- def prepare_callback(on, what, method_name = nil, params = {}, &block)
18
- set_callback(on, what) do
19
- if params[:on] == :error && error? || \
20
- params[:on] == :success && success? || params[:on].nil?
21
- block_given? ? instance_eval(&block) : self.method(method_name).call
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,4 +0,0 @@
1
- module ActiveAction
2
- class Error < StandardError
3
- end
4
- end
@@ -1,14 +0,0 @@
1
- module ActiveAction
2
- module Statuses
3
- {
4
- success: %i(success succeed done correct ready active),
5
- error: %i(error failure fail invalid incorrect inactive)
6
- }.each do |key, values|
7
- values.each do |value|
8
- define_method(:"#{value}?") { @status == key }
9
-
10
- define_method(:"#{value}!") { @status = key }
11
- end
12
- end
13
- end
14
- end
@@ -1,3 +0,0 @@
1
- module ActiveAction
2
- VERSION = '3.0.1'
3
- end