bound 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/benchmark.rb +52 -0
- data/lib/bound.rb +4 -0
- data/lib/bound/version.rb +1 -1
- data/spec/bound_spec.rb +9 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecdc27f8c70cbf71b740d8c1d49cace05dbc6fa6
|
4
|
+
data.tar.gz: 596dbd67da344d3ab3503755e1c6fe4f7c1c46f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a133d2ca72cab2dcf05425ec5442b26a617cb93230785d3008ce6261c4b9f628a42120dcd531e00fa3d1ef7a422eab3dc115daa84aed40a1a28951a56b27e61
|
7
|
+
data.tar.gz: a328984a7a01c4419f56e030b9c98e54c576a512ca59db953a2bf0f4780f4018dd320c035416dd0d331b4aae947a1e3f107e33b126bc3154f6dc306c1401370b
|
data/benchmark.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
$: << 'lib'
|
2
|
+
require 'bound'
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
TestBoundary = Bound.required(:abc, :def, :ged)
|
6
|
+
|
7
|
+
ManualBoundary = Provider = Class.new do
|
8
|
+
attr_accessor :abc, :def, :ged
|
9
|
+
end
|
10
|
+
|
11
|
+
def bench(key, &block)
|
12
|
+
result = nil
|
13
|
+
|
14
|
+
time = Benchmark.realtime { result = block.call }
|
15
|
+
puts "Benchmarking '#{key}' --> #{time}ms"
|
16
|
+
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
providers = 10_000.times.map do |i|
|
21
|
+
provider = Provider.new
|
22
|
+
provider.abc = "abc#{i}"
|
23
|
+
provider.def = "def#{i}"
|
24
|
+
provider.ged = "ged#{i}"
|
25
|
+
provider
|
26
|
+
end
|
27
|
+
|
28
|
+
bench 'bound w/ objt' do
|
29
|
+
providers.map do |provider|
|
30
|
+
TestBoundary.new(provider)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
bench 'bound w/ hash' do
|
35
|
+
providers.map do |provider|
|
36
|
+
TestBoundary.new({
|
37
|
+
:abc => provider.abc,
|
38
|
+
:def => provider.def,
|
39
|
+
:ged => provider.ged
|
40
|
+
})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
bench 'plain' do
|
45
|
+
providers.map do |provider|
|
46
|
+
test = ManualBoundary.new
|
47
|
+
test.abc = provider.abc
|
48
|
+
test.def = provider.def
|
49
|
+
test.ged = provider.ged
|
50
|
+
test
|
51
|
+
end
|
52
|
+
end
|
data/lib/bound.rb
CHANGED
data/lib/bound/version.rb
CHANGED
data/spec/bound_spec.rb
CHANGED
@@ -15,6 +15,15 @@ describe Bound do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'checks if attribute exists' do
|
19
|
+
[hash, object].each do |subject|
|
20
|
+
user = User.new(subject)
|
21
|
+
|
22
|
+
assert user.has_attribute?(:name)
|
23
|
+
assert user.has_attribute?(:age)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
18
27
|
it 'also sets all attributes with new instead of build' do
|
19
28
|
[hash, object].each do |subject|
|
20
29
|
user = User.new(subject)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Holderbaum
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- LICENSE.txt
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
|
+
- benchmark.rb
|
84
85
|
- bound.gemspec
|
85
86
|
- lib/bound.rb
|
86
87
|
- lib/bound/version.rb
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
version: '0'
|
109
110
|
requirements: []
|
110
111
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.0.
|
112
|
+
rubygems_version: 2.0.3
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Implements a nice helper for fast boundary definitions
|