konstructor 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/Rakefile +39 -11
- data/konstructor.gemspec +3 -1
- data/lib/konstructor/factory.rb +19 -5
- data/lib/konstructor/main.rb +8 -2
- data/lib/konstructor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2e01d5343a1a1b9e7e1ec11b75f657717721964
|
4
|
+
data.tar.gz: a399ad13acee21bf15a41a0b19928442b4923c8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856443c125c10b4b8110bcc4289b8d1c03894a9f8d7152873a386e2bd8a7324062e2765a445db16574f9d06852d28c20ae5676ef8ee0c07927bb450bb54b0485
|
7
|
+
data.tar.gz: 182d3b562c86109bf3d7368fbc11ccc426f03c23c7b0d990b1a1d7c6d9950a7ec50c917866a6b7099f6a3afa93f3718d4710d4b5ea001a1b797956db5a1c732c
|
data/README.md
CHANGED
@@ -239,9 +239,9 @@ since all work is done during class definition and then it's just
|
|
239
239
|
standard Ruby instance creation.
|
240
240
|
|
241
241
|
Cost of `konstructor` declaration at initial load time is roughly the
|
242
|
-
same as declaring
|
242
|
+
same as declaring 5 properties with `attr_accessor`.
|
243
243
|
```ruby
|
244
|
-
attr_accessor :one, :two, :three
|
244
|
+
attr_accessor :one, :two, :three, :four, :five
|
245
245
|
|
246
246
|
# following declaration takes the same time as above declaration
|
247
247
|
konstructor
|
@@ -254,11 +254,13 @@ for details.
|
|
254
254
|
#### Dependencies and requirements
|
255
255
|
|
256
256
|
Konstructor doesn't depend on other gems.
|
257
|
-
Requires Ruby `1.9.3` or higher.
|
257
|
+
Requires Ruby `1.9.3` or higher. Works with JRuby.
|
258
258
|
|
259
259
|
#### Thread safety
|
260
260
|
|
261
|
-
Konstructor is thread
|
261
|
+
Konstructor is thread-safe in both CRuby and JRuby,
|
262
|
+
see [Thread safety page](https://github.com/snovity/konstructor/wiki/Thread-safety)
|
263
|
+
for details.
|
262
264
|
|
263
265
|
## Contributing
|
264
266
|
|
data/Rakefile
CHANGED
@@ -12,25 +12,53 @@ task :benchmark do
|
|
12
12
|
n = 10000
|
13
13
|
|
14
14
|
Benchmark.bm(30) do |x|
|
15
|
-
x.report('def:') do
|
15
|
+
x.report('25 def:') do
|
16
16
|
n.times do
|
17
17
|
Class.new do
|
18
|
-
def
|
19
|
-
def
|
20
|
-
def
|
21
|
-
def
|
22
|
-
def
|
18
|
+
def one1; end
|
19
|
+
def two1; end
|
20
|
+
def three1; end
|
21
|
+
def four1; end
|
22
|
+
def five1; end
|
23
|
+
|
24
|
+
def one2; end
|
25
|
+
def two2; end
|
26
|
+
def three2; end
|
27
|
+
def four2; end
|
28
|
+
def five2; end
|
29
|
+
|
30
|
+
def one3; end
|
31
|
+
def two3; end
|
32
|
+
def three3; end
|
33
|
+
def four3; end
|
34
|
+
def five3; end
|
35
|
+
|
36
|
+
def one4; end
|
37
|
+
def two4; end
|
38
|
+
def three4; end
|
39
|
+
def four4; end
|
40
|
+
def five4; end
|
41
|
+
|
42
|
+
def one5; end
|
43
|
+
def two5; end
|
44
|
+
def three5; end
|
45
|
+
def four5; end
|
46
|
+
def five5; end
|
23
47
|
end
|
24
48
|
end
|
25
49
|
end
|
26
|
-
x.report('attr_accessor:') do
|
50
|
+
x.report('25 props via attr_accessor:') do
|
27
51
|
n.times do
|
28
52
|
Class.new do
|
29
|
-
attr_accessor :
|
53
|
+
attr_accessor :one1, :two1, :three1, :four1, :five1,
|
54
|
+
:one2, :two2, :three2, :four2, :five2,
|
55
|
+
:one3, :two3, :three3, :four3, :five3,
|
56
|
+
:one4, :two4, :three4, :four4, :five4,
|
57
|
+
:one5, :two5, :three5, :four5, :five5
|
30
58
|
end
|
31
59
|
end
|
32
60
|
end
|
33
|
-
x.report('
|
61
|
+
x.report(' 5 konstructors after:') do
|
34
62
|
n.times do
|
35
63
|
Class.new do
|
36
64
|
def one; end
|
@@ -43,7 +71,7 @@ task :benchmark do
|
|
43
71
|
end
|
44
72
|
end
|
45
73
|
end
|
46
|
-
x.report('
|
74
|
+
x.report(' 5 konstructors before:') do
|
47
75
|
n.times do
|
48
76
|
Class.new do
|
49
77
|
konstructor :one, :two, :three, :four, :five
|
@@ -56,7 +84,7 @@ task :benchmark do
|
|
56
84
|
end
|
57
85
|
end
|
58
86
|
end
|
59
|
-
x.report('
|
87
|
+
x.report(' 5 konstructors nameless:') do
|
60
88
|
n.times do
|
61
89
|
Class.new do
|
62
90
|
konstructor
|
data/konstructor.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require_relative 'lib/konstructor/version'
|
2
|
+
# require_relative 'lib/konstructor/version' <- doesn't work with Ruby 1.9.3 in gemspec when building gem
|
3
|
+
require File.expand_path('../lib/konstructor/version', __FILE__)
|
4
|
+
|
3
5
|
|
4
6
|
Gem::Specification.new do |spec|
|
5
7
|
spec.name = 'konstructor'
|
data/lib/konstructor/factory.rb
CHANGED
@@ -5,14 +5,16 @@ module Konstructor
|
|
5
5
|
def initialize(klass)
|
6
6
|
@klass = klass
|
7
7
|
@konstructor_names = []
|
8
|
-
|
8
|
+
# converting string to symbol for much quicker hash lookups
|
9
|
+
@thread_next_method_var_name = :"konstructor#{object_id}"
|
10
|
+
reset_next_method_is_konstructor!
|
9
11
|
end
|
10
12
|
|
11
13
|
def declare(new_names)
|
12
14
|
if new_names.empty?
|
13
|
-
|
15
|
+
next_method_is_konstructor!
|
14
16
|
else
|
15
|
-
|
17
|
+
reset_next_method_is_konstructor!
|
16
18
|
process_new_names(new_names)
|
17
19
|
end
|
18
20
|
end
|
@@ -24,8 +26,8 @@ module Konstructor
|
|
24
26
|
def method_added_to_klass(name)
|
25
27
|
name = name.to_sym
|
26
28
|
|
27
|
-
if
|
28
|
-
|
29
|
+
if next_method_is_konstructor?
|
30
|
+
reset_next_method_is_konstructor!
|
29
31
|
@konstructor_names << name
|
30
32
|
process_declaration(name)
|
31
33
|
elsif declared?(name)
|
@@ -35,6 +37,18 @@ module Konstructor
|
|
35
37
|
|
36
38
|
private
|
37
39
|
|
40
|
+
def next_method_is_konstructor!
|
41
|
+
Thread.current[@thread_next_method_var_name] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset_next_method_is_konstructor!
|
45
|
+
Thread.current[@thread_next_method_var_name] = false
|
46
|
+
end
|
47
|
+
|
48
|
+
def next_method_is_konstructor?
|
49
|
+
Thread.current[@thread_next_method_var_name]
|
50
|
+
end
|
51
|
+
|
38
52
|
def declared_in_self?(name)
|
39
53
|
@konstructor_names.include?(name.to_sym)
|
40
54
|
end
|
data/lib/konstructor/main.rb
CHANGED
@@ -67,6 +67,8 @@ module Konstructor
|
|
67
67
|
DEFAULT_NAMES = [:initialize]
|
68
68
|
RESERVED_NAMES = [:new, :initialize]
|
69
69
|
|
70
|
+
extend MonitorMixin
|
71
|
+
|
70
72
|
class << self
|
71
73
|
def reserved?(name)
|
72
74
|
RESERVED_NAMES.include?(name.to_sym)
|
@@ -90,11 +92,15 @@ module Konstructor
|
|
90
92
|
|
91
93
|
def declare(klass, new_method_names)
|
92
94
|
setup_method_added_hook(klass)
|
93
|
-
|
95
|
+
synchronize do
|
96
|
+
get_or_init_factory(klass).declare(new_method_names)
|
97
|
+
end
|
94
98
|
end
|
95
99
|
|
96
100
|
def method_added_to_klass(klass, method_name)
|
97
|
-
|
101
|
+
synchronize do
|
102
|
+
get_or_init_factory(klass).method_added_to_klass(method_name)
|
103
|
+
end
|
98
104
|
end
|
99
105
|
|
100
106
|
def is?(klass, method_name)
|
data/lib/konstructor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: konstructor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dima Lashkov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|