rails_ops 1.1.6 → 1.1.11

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: 110b35ba1ad8a634189bee84d71bf999b650e9c08fa6865a115f545805abbd45
4
- data.tar.gz: c7864d5c285d9c83f5eb9b39a2bc69620b1b650137eb486ad98d67bc26f462eb
3
+ metadata.gz: d740212b721733bcaa78e833cccbb796f9b6884cba56947c108e8639cae1b3e5
4
+ data.tar.gz: 75cca3298e678cfed1329264805b630f7e8e7ecdadf468f70f9dfbbeaef0d66b
5
5
  SHA512:
6
- metadata.gz: 9f0bbc33e9818d8ea27679ef9662c5416d6aec0da16b5d7bbca6c457396c4414883d281aea434e765e045e56aa080e67888df8b58889c078a27caa5b7fa55442
7
- data.tar.gz: c3095901ff310ef252d0c33b64d3492fbf6aad4146fc3ba2b88249fde53487575243cc92516e7f0ada275322757a2d62bfc48d21aab23f375733ba16f283a57a
6
+ metadata.gz: 4305b1afb3d47957a04277499eef15223f88932b92a1599cde5f24499daf0432bf98237736b081c01852d63413664e2176922c4478eee87e46fc282af360fc93
7
+ data.tar.gz: d5b7398bf734e1e40d734718dc1e60d85722cd252bac1b7933e2e513e640f1460f0fd11df8af346f58f0b7da30b7fa7ee6de5449ee02d9854d8cee873fbfbc8e
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.11 (2020-10-29)
4
+
5
+ * Add method `lazy_model` to `RailsOps::Operation::Model`
6
+
7
+ ## 1.1.10 (2020-08-29)
8
+
9
+ * Fix parameter inspection bug introduced in 1.1.9.
10
+
11
+ ## 1.1.9 (2020-08-28)
12
+
13
+ * Gracefully filter params when inspecting an operation. If the params included
14
+ numeric keys in `rails < 6`, this lead to an error. This error is now handeled
15
+ gracefully and params are not inspected.
16
+
17
+ * Do not call `inspect` every time an op is run
18
+
19
+ ## 1.1.8 (2020-07-08)
20
+
21
+ * Fix bug where only the first hooked operation was called
22
+
23
+ ## 1.1.7 (2020-06-18)
24
+
25
+ * Add controller / helper method `model?`
26
+
3
27
  ## 1.1.6 (2020-04-08)
4
28
 
5
29
  * Fix suppressed validation errors by operations called via hookup. Now the
data/README.md CHANGED
@@ -1361,6 +1361,9 @@ RailsOps conveniently provides you with a `model` instance method, which is a
1361
1361
  shortcut for `op.model`. This is particularly useful since this is available as
1362
1362
  a view helper method as well, see next section.
1363
1363
 
1364
+ You can check whether a model is available by using the `model?` method, which
1365
+ is available in both controllers and views.
1366
+
1364
1367
  ### View helper methods
1365
1368
 
1366
1369
  The following controller methods are automatically provided as helper methods
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.6
1
+ 1.1.11
@@ -21,6 +21,7 @@ module RailsOps
21
21
  included do
22
22
  if defined?(helper_method)
23
23
  helper_method :model
24
+ helper_method :model?
24
25
  helper_method :op
25
26
  helper_method :op?
26
27
  helper_method :op_context
@@ -85,6 +86,10 @@ module RailsOps
85
86
  return op.model
86
87
  end
87
88
 
89
+ def model?
90
+ !!(@model || op? && op.respond_to?(:model) && op.model)
91
+ end
92
+
88
93
  # Filters the `params` hash for use with RailsOps. This removes certain
89
94
  # web-specific parameters based on `EXCEPT_PARAMS`.
90
95
  def filter_op_params(params)
@@ -84,7 +84,7 @@ class RailsOps::Hookup
84
84
  op = op_class.new(context, params)
85
85
 
86
86
  begin
87
- return op.run!
87
+ op.run!
88
88
  rescue *op.validation_errors => e
89
89
  fail RailsOps::Exceptions::HookupOpValidationFailed, e
90
90
  end
@@ -107,7 +107,7 @@ class RailsOps::Operation
107
107
  # any validation exception.
108
108
  def run!
109
109
  ActiveSupport::Notifications.instrument('run.rails_ops', operation: self) do
110
- ::RailsOps::Profiler.profile(object_id, inspect) do
110
+ ::RailsOps::Profiler.profile(object_id) do
111
111
  fail 'An operation can only be performed once.' if performed?
112
112
  @performed = true
113
113
  run_policies :before_perform
@@ -125,7 +125,12 @@ class RailsOps::Operation
125
125
  def inspect
126
126
  inspection = self.class.name || '(AnonymousOp)'
127
127
  if params
128
- inspection += " (#{inspect_params(filtered_params)})"
128
+ begin
129
+ inspected_params = inspect_params(filtered_params)
130
+ rescue
131
+ inspected_params = '<could not inspect params>'
132
+ end
133
+ inspection += " (#{inspected_params})"
129
134
  end
130
135
  return inspection
131
136
  end
@@ -3,6 +3,18 @@ class RailsOps::Operation::Model < RailsOps::Operation
3
3
  include RailsOps::Mixins::Model::Nesting
4
4
 
5
5
  class_attribute :_model_class
6
+ class_attribute :_lazy_model
7
+
8
+ # Works like `model` method (see its documentation), but takes a string as
9
+ # model class and constructs the effective model class lazily on first
10
+ # invocation of the `model` method (without params).
11
+ def self.lazy_model(model_class_name = nil, name = nil, &block)
12
+ self._lazy_model = {
13
+ model_class_name: model_class_name,
14
+ name: name,
15
+ block: block
16
+ }
17
+ end
6
18
 
7
19
  # Allows to set or get a model class associated with this operation.
8
20
  #
@@ -63,6 +75,8 @@ class RailsOps::Operation::Model < RailsOps::Operation
63
75
  else
64
76
  self._model_class = model_class
65
77
  end
78
+ elsif _lazy_model && _model_class.nil?
79
+ return model(_lazy_model[:model_class_name].safe_constantize, _lazy_model[:name], &_lazy_model[:block])
66
80
  elsif _model_class.nil?
67
81
  fail 'No model class has been set.'
68
82
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rails_ops 1.1.6 ruby lib
2
+ # stub: rails_ops 1.1.11 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rails_ops".freeze
6
- s.version = "1.1.6"
6
+ s.version = "1.1.11"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2020-04-08"
11
+ s.date = "2020-10-29"
12
12
  s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE.txt".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/rails_ops.rb".freeze, "lib/rails_ops/authorization_backend/abstract.rb".freeze, "lib/rails_ops/authorization_backend/can_can_can.rb".freeze, "lib/rails_ops/configuration.rb".freeze, "lib/rails_ops/context.rb".freeze, "lib/rails_ops/controller_mixin.rb".freeze, "lib/rails_ops/exceptions.rb".freeze, "lib/rails_ops/hooked_job.rb".freeze, "lib/rails_ops/hookup.rb".freeze, "lib/rails_ops/hookup/dsl.rb".freeze, "lib/rails_ops/hookup/dsl_validator.rb".freeze, "lib/rails_ops/hookup/hook.rb".freeze, "lib/rails_ops/log_subscriber.rb".freeze, "lib/rails_ops/mixins.rb".freeze, "lib/rails_ops/mixins/authorization.rb".freeze, "lib/rails_ops/mixins/log_settings.rb".freeze, "lib/rails_ops/mixins/model.rb".freeze, "lib/rails_ops/mixins/model/authorization.rb".freeze, "lib/rails_ops/mixins/model/nesting.rb".freeze, "lib/rails_ops/mixins/param_authorization.rb".freeze, "lib/rails_ops/mixins/policies.rb".freeze, "lib/rails_ops/mixins/require_context.rb".freeze, "lib/rails_ops/mixins/routes.rb".freeze, "lib/rails_ops/mixins/schema_validation.rb".freeze, "lib/rails_ops/mixins/sub_ops.rb".freeze, "lib/rails_ops/model_casting.rb".freeze, "lib/rails_ops/model_mixins.rb".freeze, "lib/rails_ops/model_mixins/ar_extension.rb".freeze, "lib/rails_ops/model_mixins/parent_op.rb".freeze, "lib/rails_ops/model_mixins/virtual_attributes.rb".freeze, "lib/rails_ops/model_mixins/virtual_attributes/virtual_column_wrapper.rb".freeze, "lib/rails_ops/model_mixins/virtual_has_one.rb".freeze, "lib/rails_ops/model_mixins/virtual_model_name.rb".freeze, "lib/rails_ops/operation.rb".freeze, "lib/rails_ops/operation/model.rb".freeze, "lib/rails_ops/operation/model/create.rb".freeze, "lib/rails_ops/operation/model/destroy.rb".freeze, "lib/rails_ops/operation/model/load.rb".freeze, "lib/rails_ops/operation/model/update.rb".freeze, "lib/rails_ops/patches/active_type_patch.rb".freeze, "lib/rails_ops/profiler.rb".freeze, "lib/rails_ops/profiler/node.rb".freeze, "lib/rails_ops/railtie.rb".freeze, "lib/rails_ops/scoped_env.rb".freeze, "lib/rails_ops/virtual_model.rb".freeze, "rails_ops.gemspec".freeze, "test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/assets/config/manifest.js".freeze, "test/dummy/app/assets/images/.keep".freeze, "test/dummy/app/assets/javascripts/application.js".freeze, "test/dummy/app/assets/javascripts/cable.js".freeze, "test/dummy/app/assets/javascripts/channels/.keep".freeze, "test/dummy/app/assets/stylesheets/application.css".freeze, "test/dummy/app/channels/application_cable/channel.rb".freeze, "test/dummy/app/channels/application_cable/connection.rb".freeze, "test/dummy/app/controllers/application_controller.rb".freeze, "test/dummy/app/controllers/concerns/.keep".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/jobs/application_job.rb".freeze, "test/dummy/app/mailers/application_mailer.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/group.rb".freeze, "test/dummy/app/views/layouts/application.html.erb".freeze, "test/dummy/app/views/layouts/mailer.html.erb".freeze, "test/dummy/app/views/layouts/mailer.text.erb".freeze, "test/dummy/bin/bundle".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/bin/update".freeze, "test/dummy/bin/yarn".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/cable.yml".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/development.rb".freeze, "test/dummy/config/environments/production.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/application_controller_renderer.rb".freeze, "test/dummy/config/initializers/assets.rb".freeze, "test/dummy/config/initializers/backtrace_silencers.rb".freeze, "test/dummy/config/initializers/cookies_serializer.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/mime_types.rb".freeze, "test/dummy/config/initializers/rails_ops.rb".freeze, "test/dummy/config/initializers/wrap_parameters.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/config/secrets.yml".freeze, "test/dummy/config/spring.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/lib/assets/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/package.json".freeze, "test/dummy/public/404.html".freeze, "test/dummy/public/422.html".freeze, "test/dummy/public/500.html".freeze, "test/dummy/public/apple-touch-icon-precomposed.png".freeze, "test/dummy/public/apple-touch-icon.png".freeze, "test/dummy/public/favicon.ico".freeze, "test/dummy/tmp/.keep".freeze, "test/test_helper.rb".freeze, "test/unit/rails_ops/mixins/model/nesting.rb".freeze, "test/unit/rails_ops/mixins/policies_test.rb".freeze, "test/unit/rails_ops/operation/model/create_test.rb".freeze, "test/unit/rails_ops/operation/model/load_test.rb".freeze, "test/unit/rails_ops/operation/model/update_test.rb".freeze, "test/unit/rails_ops/operation/model_test.rb".freeze, "test/unit/rails_ops/operation_test.rb".freeze]
13
13
  s.rubygems_version = "3.1.2".freeze
14
14
  s.summary = "An operations service layer for rails projects.".freeze
@@ -150,4 +150,9 @@ class RailsOps::OperationTest < ActiveSupport::TestCase
150
150
  assert_equal 'RailsOps::OperationTest::BASIC_OP ({"foo"=>:bar})',
151
151
  BASIC_OP.new(foo: :bar).inspect
152
152
  end
153
+
154
+ def test_inspect_with_numeric_param_keys
155
+ assert_equal 'RailsOps::OperationTest::BASIC_OP ({1=>2})',
156
+ BASIC_OP.new(1 => 2).inspect
157
+ end
153
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler