constructor_shortcut 0.4.0 → 0.5.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
  SHA1:
3
- metadata.gz: 6642a099c707719c7c07500fbf1d45bcbfa26142
4
- data.tar.gz: 8bef539818e06c0e7ed7e45589cb908ff34e04c1
3
+ metadata.gz: 805b6127e506b5fe99c9bbe821c05d88d05d0de1
4
+ data.tar.gz: 38ed163ac7c7571df6ffb6b2e76f4776d918df32
5
5
  SHA512:
6
- metadata.gz: 5a163f39bd64e9294f6a47a06a39fe7800a1fd40f55c7e11577691e3d38e77a3585bc919a39d2604db882b184c596fd5d1ac7676c06e7a8c3abd30a203c12706
7
- data.tar.gz: 44f3c682398779f61dd8d7d78bdd20650249565603232af34900cfbc4b910c7c240f5a02abd4b53a9833d41ea6a2f736a28867e6998e65647b778e723f07d269
6
+ metadata.gz: cb4b01f3d2161e8d3217425a295b6ca40dbd64631a1c961ddc88eb1710b638724c92ccbbce518ce0ffd8ff7eb7d559f464dab9bdb4336010043343e311e664e5
7
+ data.tar.gz: 8ddd1b74de07d5a95f470a8fe1cc23e73b51de6360807d961fe60ab8d629e269277bf52e051f373d16364c21b8fcff9330c8dd24cbe0d127b79348a69df8b154
data/README.md CHANGED
@@ -33,7 +33,8 @@ After:
33
33
  ```ruby
34
34
  class CallableServiceObject
35
35
  extend Dry::Initializer
36
- extend ConstructorShortcut[:call]
36
+ # Similar to `extend ConstructorShortcut[:call, :call]`
37
+ extend ConstructorShortcut
37
38
 
38
39
  param :foo
39
40
 
@@ -0,0 +1,27 @@
1
+ # rubocop:disable Metrics/MethodLength, Style/Documentation
2
+ module ConstructorShortcut
3
+ module Cache
4
+ def self.resolve(name, class_name)
5
+ @cache ||= {}
6
+ key = "#{name.inspect}, #{class_name.inspect}".freeze
7
+
8
+ @cache[key] ||=
9
+ Module.new do
10
+ @key = key
11
+
12
+ class << self
13
+ def name
14
+ "ConstructorShortcut[#{@key}]"
15
+ end
16
+ alias_method :to_s, :name
17
+ alias_method :to_str, :name
18
+ alias_method :inspect, :name
19
+ end
20
+
21
+ define_method class_name do |*args, &block|
22
+ new(*args, &block).public_send(name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module ConstructorShortcut
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -1,28 +1,14 @@
1
1
  require "constructor_shortcut/version"
2
+ require "constructor_shortcut/cache"
2
3
 
3
4
  # Generates anonymous module containing single class method
4
5
  module ConstructorShortcut
5
6
  # Used to set method name
6
- # rubocop:disable Metrics/MethodLength
7
7
  def self.[](name = :call, class_name = :call)
8
- @cache ||= {}
9
- @cache[name] ||=
10
- Module.new do
11
- @key = name.inspect
12
-
13
- class << self
14
- def name
15
- "ConstructorShortcut[#{@key}]"
16
- end
17
- alias_method :to_s, :name
18
- alias_method :to_str, :name
19
- alias_method :inspect, :name
20
- end
8
+ Cache.resolve(name, class_name)
9
+ end
21
10
 
22
- define_method class_name do |*args, &block|
23
- new(*args, &block).public_send(name)
24
- end
25
- end
11
+ def call(*args, &block)
12
+ new(*args, &block).call
26
13
  end
27
- # rubocop:enable Metrics/MethodLength
28
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor_shortcut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-24 00:00:00.000000000 Z
11
+ date: 2019-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - bin/setup
101
101
  - constructor_shortcut.gemspec
102
102
  - lib/constructor_shortcut.rb
103
+ - lib/constructor_shortcut/cache.rb
103
104
  - lib/constructor_shortcut/version.rb
104
105
  homepage: https://github.com/gzigzigzeo/constructor_shortcut
105
106
  licenses: