ruby_peter_v 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 850938ee947f3ce50fcdcfe4162e4c62374a59b0
4
+ data.tar.gz: 88b16856fcf2b394c52f641b812dee72dfb3d1ae
5
+ SHA512:
6
+ metadata.gz: 727a2fab4b29424771d37145b69e34df45ba576baa38fc6aa296a9e0c37d69cd7a2117696ed3b67114638f36a860c26a732a130f366e3a4813ae473792767c80
7
+ data.tar.gz: d8e1653acbeefd69c46714db994da4a22169dc48f9f68a6c6c02f6aea3fd4b28cae7b67f38ee59fff3333af5d6ced489818a4641a5e113317d8a2fd5b52112cf
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ruby_peter_v
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/HISTORY.txt CHANGED
@@ -48,5 +48,10 @@
48
48
 
49
49
  * fix truncate_utf8(max_byte_size) to also work on JRuby
50
50
 
51
+ 0.0.12 (2013-10-16)
52
+
53
+ * refactor
54
+ * add validation on attribute in SetOnce
55
+
51
56
  TODO
52
57
  * Object#assert_keys_in
@@ -3,14 +3,27 @@ class RubyPeterV::SetOnceError < StandardError ; end
3
3
  class Object
4
4
 
5
5
  def set_once(attribute, value)
6
- ivar_symbol = :"@#{attribute}"
6
+ ivar_symbol = ivar_symbol(attribute)
7
7
  instance_value = instance_variable_get(ivar_symbol)
8
- if (instance_value && instance_value != value)
8
+ validate_immutable(attribute, instance_value, value)
9
+ instance_variable_set(ivar_symbol, value)
10
+ end
11
+
12
+ private
13
+
14
+ def ivar_symbol(attribute)
15
+ unless attribute.is_a?(Symbol)
16
+ raise(ArgumentError, 'first argument must be a symbol for the attribute')
17
+ end
18
+ :"@#{attribute}"
19
+ end
20
+
21
+ def validate_immutable(attribute, old_value, new_value)
22
+ if (old_value && old_value != new_value)
9
23
  raise(
10
24
  RubyPeterV::SetOnceError,
11
- "Value of #{attribute} was #{instance_value}, trying to set it to #{value}")
25
+ "Value of #{attribute} was #{old_value}, trying to set it to #{new_value}")
12
26
  end
13
- instance_variable_set(:"@#{attribute}", value)
14
27
  end
15
28
 
16
29
  end
@@ -1,3 +1,3 @@
1
1
  module RubyPeterV
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -4,6 +4,12 @@ describe "set_once" do
4
4
 
5
5
  let(:subject) { Object.new }
6
6
 
7
+ it 'raises ArgumentError when the attribute argument is not a symbol' do
8
+ lambda { subject.set_once(nil, 10) } . should raise_error(
9
+ ArgumentError,
10
+ 'first argument must be a symbol for the attribute')
11
+ end
12
+
7
13
  it "can be set when nil" do
8
14
  subject.instance_variable_get(:@attr).should be_nil # assert pre-condition
9
15
  value = 10
@@ -3,6 +3,16 @@ require 'spec_helper'
3
3
 
4
4
  describe 'truncate_utf8' do
5
5
 
6
+ context 'edge cases' do
7
+ it 'works on empty string' do
8
+ ''.truncate_utf8(140).should == ''
9
+ end
10
+
11
+ it 'works with max_byte_size = 0 ' do
12
+ 'AA'.truncate_utf8(0).should == ''
13
+ end
14
+ end
15
+
6
16
  context 'ASCII only' do
7
17
 
8
18
  let (:a120) { 'A' * 120 }
metadata CHANGED
@@ -1,80 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_peter_v
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.11
4
+ version: 0.0.12
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Vandenabeele
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2013-10-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - '>='
19
18
  - !ruby/object:Gem::Version
20
19
  version: '2'
21
- none: false
22
- requirement: !ruby/object:Gem::Requirement
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2'
27
- none: false
28
- prerelease: false
29
- type: :development
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: guard-rspec
32
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: !ruby/object:Gem::Requirement
33
30
  requirements:
34
31
  - - '>='
35
32
  - !ruby/object:Gem::Version
36
33
  version: '0'
37
- none: false
38
- requirement: !ruby/object:Gem::Requirement
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
39
37
  requirements:
40
38
  - - '>='
41
39
  - !ruby/object:Gem::Version
42
40
  version: '0'
43
- none: false
44
- prerelease: false
45
- type: :development
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rb-fsevent
48
- version_requirements: !ruby/object:Gem::Requirement
43
+ requirement: !ruby/object:Gem::Requirement
49
44
  requirements:
50
45
  - - ~>
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0.9'
53
- none: false
54
- requirement: !ruby/object:Gem::Requirement
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
55
51
  requirements:
56
52
  - - ~>
57
53
  - !ruby/object:Gem::Version
58
54
  version: '0.9'
59
- none: false
60
- prerelease: false
61
- type: :development
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: terminal-notifier-guard
64
- version_requirements: !ruby/object:Gem::Requirement
57
+ requirement: !ruby/object:Gem::Requirement
65
58
  requirements:
66
59
  - - '>='
67
60
  - !ruby/object:Gem::Version
68
61
  version: '0'
69
- none: false
70
- requirement: !ruby/object:Gem::Requirement
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - '>='
73
67
  - !ruby/object:Gem::Version
74
68
  version: '0'
75
- none: false
76
- prerelease: false
77
- type: :development
78
69
  description: Ruby helpers for @peter_v
79
70
  email:
80
71
  - peter@vandenabeele.com
@@ -84,7 +75,8 @@ extra_rdoc_files: []
84
75
  files:
85
76
  - .gitignore
86
77
  - .rspec
87
- - .rvmrc
78
+ - .ruby-gemset
79
+ - .ruby-version
88
80
  - .travis.yml
89
81
  - Gemfile
90
82
  - Guardfile
@@ -108,7 +100,8 @@ files:
108
100
  - spec/spec_helper.rb
109
101
  homepage: https://github.com/petervandenabeele/ruby_peter_v
110
102
  licenses: []
111
- post_install_message:
103
+ metadata: {}
104
+ post_install_message:
112
105
  rdoc_options: []
113
106
  require_paths:
114
107
  - lib
@@ -117,18 +110,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
110
  - - '>='
118
111
  - !ruby/object:Gem::Version
119
112
  version: '0'
120
- none: false
121
113
  required_rubygems_version: !ruby/object:Gem::Requirement
122
114
  requirements:
123
115
  - - '>='
124
116
  - !ruby/object:Gem::Version
125
117
  version: '0'
126
- none: false
127
118
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 1.8.24
130
- signing_key:
131
- specification_version: 3
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.3
121
+ signing_key:
122
+ specification_version: 4
132
123
  summary: Ruby helpers for @peter_v
133
124
  test_files:
134
125
  - spec/lib/ruby_peter_v/define_equality_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use --create 2.0.0@ruby_peter_v