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 +4 -4
- data/README.md +2 -1
- data/lib/constructor_shortcut/cache.rb +27 -0
- data/lib/constructor_shortcut/version.rb +1 -1
- data/lib/constructor_shortcut.rb +5 -19
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 805b6127e506b5fe99c9bbe821c05d88d05d0de1
|
4
|
+
data.tar.gz: 38ed163ac7c7571df6ffb6b2e76f4776d918df32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4b01f3d2161e8d3217425a295b6ca40dbd64631a1c961ddc88eb1710b638724c92ccbbce518ce0ffd8ff7eb7d559f464dab9bdb4336010043343e311e664e5
|
7
|
+
data.tar.gz: 8ddd1b74de07d5a95f470a8fe1cc23e73b51de6360807d961fe60ab8d629e269277bf52e051f373d16364c21b8fcff9330c8dd24cbe0d127b79348a69df8b154
|
data/README.md
CHANGED
@@ -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
|
data/lib/constructor_shortcut.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
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
|
-
|
23
|
-
|
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
|
+
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-
|
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:
|