crossbeam 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3e5a2f8df4b98114b1f734e78e22332078ea4f9f933fea9fe745f4113e1dab9
4
- data.tar.gz: aae8768c3bd775c9e0939ae73b738b0ae2b00f50e2c1719116870f15e7fb3da4
3
+ metadata.gz: b64e651b82a1643650011351595188dafc9c609e42b4051d73cf75a9611cb2a8
4
+ data.tar.gz: 9d51296e74fdc2b014c916124d77427ecb12a7e8d90584fd8286e15a78acc1e5
5
5
  SHA512:
6
- metadata.gz: 0c9c6b21bcf8058137a42317c0e18b24ec6cb9aaeb06ad34dacd318c38931c29bed9d657e66390f41e2df3462dbb5fd955c5438d3c6f10603bb94429099b0888
7
- data.tar.gz: 80d02b81f62a3d9670802576cb27794050925ef15335b9b2472816813d5ba83286147855596c5ad73a388c7a9c4193c7ba894d5e873353a5a03f6e2988e2f6c5
6
+ metadata.gz: f12b259277b699799db158302015ce6dcef771c38f2a74acaa8c15185e9389bdc3b2f23d7ed9cde55d411845cda7e4f24ae121f2f2bb421fdbc8f29305e865c3
7
+ data.tar.gz: fdae532476ab1a4900225550690599b15268d5c87a7d912e3553b8a5f7c1bf5022b18b4a098f60ef083f123912aa7e7a8a3aa7013774c675c4683b22d7b5f3fe
data/README.md CHANGED
@@ -206,7 +206,7 @@ class Bar
206
206
  end
207
207
  end
208
208
 
209
- after_hours = Bar.call(age: 15, drink: 'tran')
209
+ after_hours = Bar.call(age: 15, drink: 'tanqueray')
210
210
  puts after_hours.errors.full_messages if after_hours.errors?
211
211
  # => Age must be greater than or equal to 21
212
212
  # => Drink is not included in the list
data/defs.rbi CHANGED
@@ -256,11 +256,11 @@ module Crossbeam
256
256
  def run_after_callbacks; end
257
257
 
258
258
  # Create a list of `after` callback methods and/or blocks
259
- sig { returns(T::Hash[T.untyped, T.untyped]) }
259
+ sig { returns(T::Array[T.untyped]) }
260
260
  def after_callbacks; end
261
261
 
262
262
  # Create a list of `before` callback methods and/or blocks
263
- sig { returns(T::Hash[T.untyped, T.untyped]) }
263
+ sig { returns(T::Array[T.untyped]) }
264
264
  def before_callbacks; end
265
265
 
266
266
  # Loopthrough and run all the classes listed callback methods
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './error'
3
+ require_relative 'error'
4
4
 
5
5
  module Crossbeam
6
6
  # Callbacks before/after the services `call` is called
@@ -22,7 +22,7 @@ module Crossbeam
22
22
  # Add callback `before` method or block
23
23
  #
24
24
  # @param callbacks [Hash]
25
- # @return [void]
25
+ # @return [Void]
26
26
  # @yield An optional block to instance_exec(&block) || instance_eval(&block)
27
27
  def before(*callbacks, &block)
28
28
  callbacks << block if block
@@ -32,7 +32,7 @@ module Crossbeam
32
32
  # Add callback `after` method or block
33
33
  #
34
34
  # @param callbacks [Hash]
35
- # @return [void]
35
+ # @return [Void]
36
36
  # @yield An optional block to instance_exec(&block) || instance_eval(&block)
37
37
  def after(*callbacks, &block)
38
38
  callbacks << block if block
@@ -41,7 +41,7 @@ module Crossbeam
41
41
 
42
42
  # Call all callbacks before `#call` is referenced (methods, blocks, etc.)
43
43
  #
44
- # @return [void]
44
+ # @return [Void]
45
45
  def run_before_callbacks
46
46
  # run_callbacks(self.class.before_callbacks)
47
47
  run_callbacks(before_callbacks)
@@ -49,21 +49,21 @@ module Crossbeam
49
49
 
50
50
  # Call and run all callbacks after `#call` has ran
51
51
  #
52
- # @return [void]
52
+ # @return [Void]
53
53
  def run_after_callbacks
54
54
  run_callbacks(after_callbacks)
55
55
  end
56
56
 
57
57
  # Create a list of `after` callback methods and/or blocks
58
58
  #
59
- # @return [Hash]
59
+ # @return [Array]
60
60
  def after_callbacks
61
61
  @after_callbacks ||= []
62
62
  end
63
63
 
64
64
  # Create a list of `before` callback methods and/or blocks
65
65
  #
66
- # @return [Hash]
66
+ # @return [Array]
67
67
  def before_callbacks
68
68
  @before_callbacks ||= []
69
69
  end
@@ -71,7 +71,7 @@ module Crossbeam
71
71
  # Loopthrough and run all the classes listed callback methods
72
72
  #
73
73
  # @param callbacks [Array<String, Symbol>] a list of methods to be called
74
- # @return [void]
74
+ # @return [Void]
75
75
  def run_callbacks(callbacks)
76
76
  callbacks.each { |callback| run_callback(callback) }
77
77
  end
@@ -82,7 +82,7 @@ module Crossbeam
82
82
  #
83
83
  # @param callback [Symbol]
84
84
  # @param options [Hash]
85
- # @return [void]
85
+ # @return [Void]
86
86
  def run_callback(callback, *options)
87
87
  # Ensure the initialize instance class has been called and passed
88
88
  return unless @klass
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './error'
3
+ require_relative 'error'
4
4
 
5
5
  module Crossbeam
6
6
  # Very similar to ActiveModel errors
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './error'
3
+ require_relative 'error'
4
4
 
5
5
  module Crossbeam
6
6
  # For forcing specific output after `#call`
@@ -19,7 +19,7 @@ module Crossbeam
19
19
 
20
20
  # Methods to load in the service object as class methods
21
21
  module ClassMethods
22
- # @return [Hash]
22
+ # @return [Array]
23
23
  CB_ALLOWED_OUTPUTS = [NilClass, String, Symbol].freeze
24
24
  # Used to specify an attribute/instance variable that should be used too return instead of @result
25
25
  #
@@ -51,16 +51,17 @@ module Crossbeam
51
51
  # @return [Hash]
52
52
  def set_results_output
53
53
  return unless @klass
54
- return unless output? && @klass.instance_variable_defined?("@#{output_param}")
54
+ return unless output? && @klass.instance_variable_defined?(:"@#{output_param}")
55
55
 
56
- @result.results = @klass.instance_variable_get("@#{output_param}")
56
+ @result.results = @klass.instance_variable_get(:"@#{output_param}")
57
57
  end
58
58
 
59
59
  # Add errors to @result.errors
60
60
  #
61
61
  # @return [Void]
62
62
  def build_error_list
63
- return unless @klass && @klass&.errors&.any?
63
+ return if @klass.nil?
64
+ return unless @klass&.errors&.any?
64
65
 
65
66
  @klass.errors.each do |error|
66
67
  # options is usually passed with an ActiveRecord validation error
@@ -77,14 +78,14 @@ module Crossbeam
77
78
  # @return [Void]
78
79
  def reassign_results
79
80
  @result.results = nil
80
- @result.results = @klass.instance_variable_get("@#{output_param}") if specified_output?
81
+ @result.results = @klass.instance_variable_get(:"@#{output_param}") if specified_output?
81
82
  end
82
83
 
83
84
  # Does the klass have an assigned output
84
85
  #
85
86
  # @return [Boolean]
86
87
  def specified_output?
87
- output? && @klass.instance_variable_defined?("@#{output_param}")
88
+ output? && @klass.instance_variable_defined?(:"@#{output_param}")
88
89
  end
89
90
 
90
91
  # Used hold the parameter which can/will be used instead of @result
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'active_model'
4
4
  # Crossbeam files
5
- require_relative './error'
6
- require_relative './errors'
5
+ require_relative 'error'
6
+ require_relative 'errors'
7
7
 
8
8
  module Crossbeam
9
9
  # Used as a data container to hold a service calls results, errors, etc.
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Crossbeam
4
4
  # @return [String]
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
data/lib/crossbeam.rb CHANGED
@@ -89,11 +89,11 @@ module Crossbeam
89
89
  # Used to determine the current state of the service call
90
90
  #
91
91
  # @return [Boolean]
92
- define_method("#{attr}?") do
92
+ define_method(:"#{attr}?") do
93
93
  return false unless @result
94
94
 
95
95
  attr = attr.to_s
96
- @result.send("#{attr}?".to_sym) || false
96
+ @result.send(:"#{attr}?") || false
97
97
  end
98
98
  end
99
99
 
@@ -5,7 +5,7 @@ if defined?(Rails)
5
5
  require 'rails/generators'
6
6
 
7
7
  # Used to generate a Rails service object
8
- class CrossbeamGenerator < ::Rails::Generators::Base
8
+ class CrossbeamGenerator < Rails::Generators::Base
9
9
  source_root File.expand_path(File.join('.', 'templates'), File.dirname(__FILE__))
10
10
 
11
11
  argument :class_name, type: :string
@@ -19,7 +19,7 @@ if defined?(Rails)
19
19
 
20
20
  # @return [void]
21
21
  def generate_test
22
- return unless Rails&.application&.config&.generators&.test_framework == :rspec
22
+ return unless Rails.application&.config&.generators&.test_framework == :rspec
23
23
 
24
24
  template 'service_spec.rb.tt', "spec/services/#{filename}_spec.rb", force: true
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crossbeam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hicks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-18 00:00:00.000000000 Z
11
+ date: 2024-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.3.15
145
+ rubygems_version: 3.5.3
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: An easy way to create and run service objects with callbacks, validations,