convenient_service 0.8.0 → 0.9.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,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d53f96dab5d2b97b26168f4859dc0daefe41c8768e83e607d13234c2c7d77101
4
- data.tar.gz: c6d5a9d30e5c3c768f556eb7d84b558099fcbeb96dbff655b7bd2b553435a26a
3
+ metadata.gz: 7bd38d2c3dd6b1e8a5d8baf78b0b017a2e8f46bf17a1099221da1c3f1b6da0cc
4
+ data.tar.gz: eb5f1bad44ec8d80c6e4b661e354c59c170bb0174dcf9f8c9ee9902f434a3cc4
5
5
  SHA512:
6
- metadata.gz: 9f3fb867003d44c6786446fdb2baac4550bd6ac8f34ee9196ee310912c4eb2084f40dc731dce8a2af7ac8a963d6a3579c6e886ad28251c4bf5a9a08ca290a6d2
7
- data.tar.gz: e24704e463ac31d3f65a4c9a5777617157bdebb62ab785e92f3f18125d8968e5c3a6d44368553c706c9f8bab0ce7bd8f938ce53ebc1df68585493738533ef2cb
6
+ metadata.gz: fef2d2dda95a3386ebc25494c003053fd72746fac690a4d7b4e1acd4b2eaadf1f858e85ec7340f0a451dc1e658dd288570a1c424671fd47112576870b18935b3
7
+ data.tar.gz: 055ec4a62139d303a21c058088fb92cea5eae7d520e4f112445a410049564e3c16c23917ac60884b349673e6174a2a16208b58748eb1eb1df6b241a84f327673
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.0](https://github.com/marian13/convenient_service/compare/v0.8.0...v0.9.0) (2023-02-22)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **export:** add a logic that forbids to use export in classes ([ca81536a](https://github.com/marian13/convenient_service/commit/ca81536a3080661cb762d549f4ef3ce1456bc566))
9
+
10
+
11
+ ### Features
12
+
13
+ * **has_result_short_syntax:** introduce Result#ud, Result#um, Result#uc ([95856c9](https://github.com/marian13/convenient_service/commit/95856c921c14888a3253f1c3d12453dbfd97a14b))
14
+ * **utils:** introduce Object#memoize_including_falsy_values ([22b2430](https://github.com/marian13/convenient_service/commit/22b2430f2a57dbded706754261defc53ec140e4f))
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **export:** add a logic that forbids to use export in classes ([ca81536a](https://github.com/marian13/convenient_service/commit/ca81536a3080661cb762d549f4ef3ce1456bc566))
20
+
3
21
  ## [0.8.0](https://github.com/marian13/convenient_service/compare/v0.7.0...v0.8.0) (2023-02-20)
4
22
 
5
23
 
@@ -13,11 +13,43 @@ module ConvenientService
13
13
 
14
14
  instance_methods do
15
15
  ##
16
- # NOTE: `Support::Delegate` is NOT used intentionally in order to NOT pollute the public interface.
16
+ # @param key [String, Symbol]
17
+ # @return [Object] Can be any type.
18
+ #
19
+ # @internal
20
+ # NOTE: Delegates to `data` instead of aliasing in order to have an ability
21
+ # to use the same RSpec stubs for short and usual syntax.
22
+ #
23
+ # For example:
24
+ #
25
+ # allow(result).to receive(:data).with(:foo).and_call_original
26
+ #
27
+ # works for both `result.data[:foo]` and `result[:foo]`.
17
28
  #
18
29
  def [](key)
19
30
  data[key]
20
31
  end
32
+
33
+ ##
34
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Data]
35
+ #
36
+ def ud
37
+ unsafe_data
38
+ end
39
+
40
+ ##
41
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Message]
42
+ #
43
+ def um
44
+ unsafe_message
45
+ end
46
+
47
+ ##
48
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code]
49
+ #
50
+ def uc
51
+ unsafe_code
52
+ end
21
53
  end
22
54
  end
23
55
  end
@@ -68,6 +68,20 @@ module ConvenientService
68
68
  super(message)
69
69
  end
70
70
  end
71
+
72
+ class NotModule < ConvenientService::Error
73
+ ##
74
+ # @param klass [Class]
75
+ # @return [void]
76
+ #
77
+ def initialize(klass:)
78
+ message = <<~TEXT
79
+ `#{klass.inspect}` is NOT a Module.
80
+ TEXT
81
+
82
+ super(message)
83
+ end
84
+ end
71
85
  end
72
86
  end
73
87
  end
@@ -6,6 +6,14 @@ module ConvenientService
6
6
  module Export
7
7
  include Support::Concern
8
8
 
9
+ ##
10
+ # @param klass [Class, Module]
11
+ # @return [Module]
12
+ #
13
+ included do |klass|
14
+ raise Errors::NotModule.new(klass: klass) unless klass.instance_of?(::Module)
15
+ end
16
+
9
17
  class_methods do
10
18
  ##
11
19
  # @param full_name [String, Symbol]
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ #
5
+ #
6
+ module ConvenientService
7
+ module Utils
8
+ module Object
9
+ ##
10
+ # Can be used instead of `return @ivar if defined? @ivar`.
11
+ # @see https://www.justinweiss.com/articles/4-simple-memoization-patterns-in-ruby-and-one-gem/
12
+ #
13
+ # @note: `false` and `nil` are the only values that are considered `falsy` in Ruby.
14
+ # @see https://riptutorial.com/ruby/example/2092/truthy-and-falsy-values
15
+ # @see https://www.ruby-lang.org/en/documentation/faq/6/
16
+ #
17
+ # @internal
18
+ # NOTE: `falsy` is probably more common than `falsey`.
19
+ # - https://developer.mozilla.org/en-US/docs/Glossary/Falsy
20
+ #
21
+ class MemoizeIncludingFalsyValues < Support::Command
22
+ ##
23
+ # @!attribute [r] object
24
+ # @return [Object]
25
+ #
26
+ attr_reader :object
27
+
28
+ ##
29
+ # @!attribute [r] ivar_name
30
+ # @return [Symbol, String]
31
+ #
32
+ attr_reader :ivar_name
33
+
34
+ ##
35
+ # @!attribute [r] value_block
36
+ # @return [Proc, nil]
37
+ #
38
+ attr_reader :value_block
39
+
40
+ ##
41
+ # @param object [Object]
42
+ # @param ivar_name [Symbol]
43
+ # @param value_block [Proc]
44
+ # @return [void]
45
+ #
46
+ def initialize(object, ivar_name, &value_block)
47
+ @object = object
48
+ @ivar_name = ivar_name
49
+ @value_block = value_block
50
+ end
51
+
52
+ ##
53
+ # @return [Object] Value of ivar. Can be any type.
54
+ #
55
+ def call
56
+ Utils::Object.instance_variable_fetch(object, ivar_name, &value_block)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "object/instance_variable_delete"
4
4
  require_relative "object/instance_variable_fetch"
5
+ require_relative "object/memoize_including_falsy_values"
5
6
  require_relative "object/resolve_type"
6
7
 
7
8
  module ConvenientService
@@ -24,6 +25,16 @@ module ConvenientService
24
25
  InstanceVariableFetch.call(...)
25
26
  end
26
27
 
28
+ ##
29
+ # @example
30
+ # object = Object.new.tap { |object| object.instance_eval { self.class.attr_reader :foo } }
31
+ #
32
+ # ConvenientService::Utils::Object.memoize_including_falsy_values(object, :@foo) { false }
33
+ #
34
+ def memoize_including_falsy_values(...)
35
+ MemoizeIncludingFalsyValues.call(...)
36
+ end
37
+
27
38
  ##
28
39
  # @example
29
40
  # ConvenientService::Utils::Object.resolve_type("foo")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConvenientService
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convenient_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marian Kostyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -728,7 +728,6 @@ files:
728
728
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb
729
729
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax.rb
730
730
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb
731
- - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern/instance_methods.rb
732
731
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step.rb
733
732
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/concern.rb
734
733
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize.rb
@@ -907,6 +906,7 @@ files:
907
906
  - lib/convenient_service/utils/object.rb
908
907
  - lib/convenient_service/utils/object/instance_variable_delete.rb
909
908
  - lib/convenient_service/utils/object/instance_variable_fetch.rb
909
+ - lib/convenient_service/utils/object/memoize_including_falsy_values.rb
910
910
  - lib/convenient_service/utils/object/resolve_type.rb
911
911
  - lib/convenient_service/utils/proc.rb
912
912
  - lib/convenient_service/utils/proc/conjunct.rb
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConvenientService
4
- module Service
5
- module Plugins
6
- module HasResult
7
- module Entities
8
- class Result
9
- module Plugins
10
- module HasResultShortSyntax
11
- module Concern
12
- module InstanceMethods
13
- ##
14
- # NOTE: `Support::Delegate` is NOT used intentionally in order to NOT pollute the public interface.
15
- #
16
- def [](key)
17
- data[key]
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end