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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbbe3eeeb3fc4c0d7ba43f0ee1f919a8dae035e1
4
- data.tar.gz: 94f41af4993edf43b4b54031eff007b25be52c1e
3
+ metadata.gz: ecdc27f8c70cbf71b740d8c1d49cace05dbc6fa6
4
+ data.tar.gz: 596dbd67da344d3ab3503755e1c6fe4f7c1c46f6
5
5
  SHA512:
6
- metadata.gz: c4675a46b510b8df00e9688288f05d572cc1fe48f2b13dfea32943b2974379533191bc1e2627876ca5aff3a3ef56360f6f7095c005225ad134734bc4c0b7ad1f
7
- data.tar.gz: 30d0f365d8bdb9a1a5febff2d86d4a658b20eb3382118369d819be2669a4eb8e5769b67c9f5739b0597a6663cb357baa6565effdf969d4aed4514b7af730569d
6
+ metadata.gz: 1a133d2ca72cab2dcf05425ec5442b26a617cb93230785d3008ce6261c4b9f628a42120dcd531e00fa3d1ef7a422eab3dc115daa84aed40a1a28951a56b27e61
7
+ data.tar.gz: a328984a7a01c4419f56e030b9c98e54c576a512ca59db953a2bf0f4780f4018dd320c035416dd0d331b4aae947a1e3f107e33b126bc3154f6dc306c1401370b
@@ -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
@@ -219,6 +219,10 @@ class Bound
219
219
  end
220
220
  end
221
221
 
222
+ def has_attribute?(attr)
223
+ self.class.attrs.keys.include? attr
224
+ end
225
+
222
226
  def __attributes__
223
227
  puts "BoundClass#__attributes__ is deprecated: use get_attributes"
224
228
  get_attributes.map(&:name)
@@ -1,3 +1,3 @@
1
1
  class Bound
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.5
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: 2013-10-02 00:00:00.000000000 Z
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.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