eac_ruby_utils 0.113.0 → 0.115.0

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: 3e7deaaf568625e32fc58c45b43ef41e125924595707b3a2ca2ea394d9dc4393
4
- data.tar.gz: 4af93c26f87f2918f36cc18b2ad5e3cefa8d6fe6a21bb09282f0112bd2138182
3
+ metadata.gz: be84b8b3b5f7b60b56a999c8aa958747cf415dc143ed654f192bbcfd7b3d0d1d
4
+ data.tar.gz: ca5988e39fe2641aac05312f9ceb18d3a96c1a9d47491832a52a796c7df1a064
5
5
  SHA512:
6
- metadata.gz: 8144e44599f8dc4b5299a3353e79fc51fa558bcb085e1d8a46d0f40182d06b9c0481f56a4a8b464bddf00a52c67c97d3846875489f90f24d0eba8e87b5ed4384
7
- data.tar.gz: 657df0404c6f3060e756198aeeb1181b210b7d18564e4b58437a5d79601e3c62d1f2d5bdb686b221b434c2ad81322817798ea329b77b94c2b110c189631055e0
6
+ metadata.gz: b21dcf87a2778009eb8571d78aa533e0a1806603c7a298bb181dd0ce3a18cccec688fca12b45954d61abe590a22c538738a0ae570d21a61d03a002f9d4fe74a2
7
+ data.tar.gz: '099e597c3949a781819a89a9d8c57eaa246696ee50c7d42e93a56e5e8fb5c7111c68042ed3bc483b9e6db68622b1311622a99a9c3d360c3f9733a86f7003fa24'
@@ -8,10 +8,10 @@ module EacRubyUtils
8
8
  #
9
9
  # Usage:
10
10
  #
11
- # require 'eac_ruby_utils/abstract_methods'
11
+ # require 'eac_ruby_utils/acts_as_abstract'
12
12
  #
13
13
  # class BaseClass
14
- # include EacRubyUtils::AbstractMethods
14
+ # include EacRubyUtils::ActsAsAbstract
15
15
  #
16
16
  # abstract_methods :mymethod
17
17
  # end
@@ -25,23 +25,44 @@ module EacRubyUtils
25
25
  # end
26
26
  #
27
27
  # SubClass.new.mymethod # return "Implemented"
28
- module AbstractMethods
28
+ module ActsAsAbstract
29
29
  common_concern
30
30
 
31
31
  class << self
32
32
  def abstract?(a_class)
33
- a_class.self_included_modules.include?(::EacRubyUtils::AbstractMethods)
33
+ a_class.self_included_modules.include?(::EacRubyUtils::ActsAsAbstract)
34
34
  end
35
35
  end
36
36
 
37
37
  module ClassMethods
38
+ # @param name [Symbol]
39
+ # @param arguments [Enumerable<Symbol>]
40
+ # @return [void]
41
+ def abstract_method(name, *arguments)
42
+ define_method name.to_sym do |*_the_args|
43
+ raise_abstract_method(name.to_sym, arguments)
44
+ end
45
+ end
46
+
47
+ # @param methods_names [Enumerable<Object>] Each item can be a symbolizable or a hash.
48
+ # @return [void]
38
49
  def abstract_methods(*methods_names)
39
50
  methods_names.each do |method_name|
40
- define_method method_name do
41
- raise_abstract_method(method_name)
51
+ if method_name.is_a?(::Hash)
52
+ abstract_methods_from_hash(method_name)
53
+ else
54
+ abstract_method(method_name)
42
55
  end
43
56
  end
44
57
  end
58
+
59
+ private
60
+
61
+ # @param hash [Hash]
62
+ # @return [void]
63
+ def abstract_methods_from_hash(hash)
64
+ hash.each { |name, arguments| abstract_method(name, *arguments) }
65
+ end
45
66
  end
46
67
 
47
68
  module InstanceMethods
@@ -59,9 +80,9 @@ module EacRubyUtils
59
80
  self.class.abstract_methods.include?(method_name.to_sym)
60
81
  end
61
82
 
62
- def raise_abstract_method(method_name)
63
- raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\"" \
64
- " (Class: #{self.class})"
83
+ def raise_abstract_method(method_name, arguments = [])
84
+ raise ::NoMethodError, "Abstract method #{method_name}(#{arguments.join(', ')}) hit in " \
85
+ "#{self}\" (Class: #{self.class})"
65
86
  end
66
87
  end
67
88
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/abstract_methods'
3
+ require 'eac_ruby_utils/acts_as_abstract'
4
4
 
5
5
  class Class
6
6
  def abstract?
7
- ::EacRubyUtils::AbstractMethods.abstract?(self)
7
+ ::EacRubyUtils::ActsAsAbstract.abstract?(self)
8
8
  end
9
9
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/abstract_methods'
3
+ require 'eac_ruby_utils/patches/module/acts_as_abstract'
4
4
 
5
5
  class Module
6
+ # @deprecated Use {#acts_as_abstract} instead.
6
7
  def enable_abstract_methods(*methods)
7
- include ::EacRubyUtils::AbstractMethods
8
- abstract_methods(*methods)
8
+ acts_as_abstract(*methods)
9
9
  end
10
10
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/acts_as_abstract'
4
+
5
+ class Module
6
+ # Include [EacRubyUtils::ActsAsAbstract] and perform EacRubyUtils::ActsAsAbstract.abstract_methods
7
+ # on parameter +methods+.
8
+ # @param methods [Array<Symbol>]
9
+ # @return [void]
10
+ def acts_as_abstract(*methods)
11
+ include ::EacRubyUtils::ActsAsAbstract
12
+ abstract_methods(*methods)
13
+ end
14
+ end
@@ -3,7 +3,11 @@
3
3
  require 'pathname'
4
4
 
5
5
  class Pathname
6
+ # @param suffix [String]
7
+ # @return [Pathname]
6
8
  def basename_sub(suffix = '')
7
- parent.join(yield(basename(suffix)))
9
+ new_basename = basename(suffix)
10
+ new_basename = yield(new_basename) if block_given?
11
+ parent.join(new_basename)
8
12
  end
9
13
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/abstract_methods'
3
+ require 'eac_ruby_utils/acts_as_abstract'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Speaker
7
7
  module Receiver
8
8
  extend ::ActiveSupport::Concern
9
- extend ::EacRubyUtils::AbstractMethods
9
+ extend ::EacRubyUtils::ActsAsAbstract
10
10
 
11
11
  module ClassMethods
12
12
  def on(*args, &block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.113.0'
4
+ VERSION = '0.115.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.113.0
4
+ version: 0.115.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-10 00:00:00.000000000 Z
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,7 +128,7 @@ extra_rdoc_files: []
128
128
  files:
129
129
  - README.rdoc
130
130
  - lib/eac_ruby_utils.rb
131
- - lib/eac_ruby_utils/abstract_methods.rb
131
+ - lib/eac_ruby_utils/acts_as_abstract.rb
132
132
  - lib/eac_ruby_utils/arguments_consumer.rb
133
133
  - lib/eac_ruby_utils/bit.rb
134
134
  - lib/eac_ruby_utils/bit_array.rb
@@ -234,6 +234,7 @@ files:
234
234
  - lib/eac_ruby_utils/patches/kernel/nyi.rb
235
235
  - lib/eac_ruby_utils/patches/module.rb
236
236
  - lib/eac_ruby_utils/patches/module/abstract_methods.rb
237
+ - lib/eac_ruby_utils/patches/module/acts_as_abstract.rb
237
238
  - lib/eac_ruby_utils/patches/module/common_concern.rb
238
239
  - lib/eac_ruby_utils/patches/module/compare_by.rb
239
240
  - lib/eac_ruby_utils/patches/module/context.rb