value_struct 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ Gemfile.lock
2
2
  doc/
3
3
  pkg/
4
4
  vendor/cache/*.gem
5
+ *~
@@ -1,4 +1,7 @@
1
- ### 0.1.0 / 2012-11-01
1
+ ### 0.6.0
2
+ * Fix specs
3
+ * Fix #dup
2
4
 
3
- * Initial release:
5
+ ### 0.5.0 / 2012-11-03
4
6
 
7
+ * Initial puplic release:
data/README.md CHANGED
@@ -55,10 +55,6 @@ Because of the nature of Ruby, most things are not really immutable. So if you h
55
55
 
56
56
  $ gem install value_struct
57
57
 
58
- ## Todo
59
-
60
- * Make test suite clean and useful
61
-
62
58
  ## Influenced by / Thanks to
63
59
 
64
60
  * Ruby Rogues #123
@@ -3,6 +3,7 @@ require_relative 'value_struct/core'
3
3
  require_relative 'value_struct/to_h'
4
4
  require_relative 'value_struct/dup_with_changes'
5
5
  require_relative 'value_struct/strict_arguments'
6
+ require_relative 'value_struct/clone'
6
7
  require_relative 'value_struct/freeze'
7
8
 
8
9
  class ValueStruct < Struct
@@ -0,0 +1,5 @@
1
+ module ValueStruct::Clone
2
+ def clone
3
+ self
4
+ end
5
+ end
@@ -2,12 +2,12 @@ module ValueStruct::DupWithChanges
2
2
  def dup(changes = {})
3
3
  case changes
4
4
  when {}
5
- new(values)
5
+ self.class.new(*values)
6
6
  when Hash
7
- new(
8
- members.zip(values).map{ |member, value|
9
- if changes.has_key?(m)
10
- changes[m]
7
+ self.class.new(
8
+ *members.zip(values).map{ |member, value|
9
+ if changes.has_key?(member)
10
+ changes[member]
11
11
  else
12
12
  value
13
13
  end
@@ -1,3 +1,3 @@
1
1
  class ValueStruct < Struct
2
- VERSION = '0.5.0'
3
- end
2
+ VERSION = '0.6.0'
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe ValueStruct::Clone do
4
+ subject do
5
+ ValueStruct.new_with_mixins(:x, :y, [ValueStruct::Clone]).new(1,2)
6
+ end
7
+
8
+ it{ subject.object_id.should == subject.clone.object_id }
9
+ it{ subject.object_id.should_not == subject.dup.object_id }
10
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe ValueStruct::DupWithChanges do
4
+ subject do
5
+ ValueStruct.new_with_mixins(:x, :y, [ValueStruct::DupWithChanges]).new(1,2)
6
+ end
7
+
8
+ context 'no arguments' do
9
+ it 'is equal' do
10
+ subject.should == subject.dup
11
+ end
12
+
13
+ it 'is another object' do
14
+ subject.object_id.should_not == subject.dup.object_id
15
+ end
16
+ end
17
+
18
+ context 'with arguments' do
19
+ let(:modified){ subject.dup(y: 5) }
20
+ it 'is equal, except for the changed field' do
21
+ subject.x.should == modified.x
22
+ subject.y.should_not == modified.y
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ValueStruct::Freeze do
4
+ subject do
5
+ ValueStruct.new_with_mixins(:x, :y, [ValueStruct::Freeze]).new
6
+ end
7
+
8
+ it 'freezes new instances' do
9
+ should be_frozen
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe ValueStruct::StrictArguments do
4
+ subject do
5
+ ValueStruct.new_with_mixins(:x, :y, [ValueStruct::StrictArguments]).new
6
+ end
7
+
8
+ it 'raises argument errors if not given the right number of arguments' do
9
+ lambda{
10
+ subject.new
11
+ }.should raise_error(ArgumentError, 'wrong number of arguments (0 for 2)')
12
+ end
13
+ end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ValueStruct do
4
- it "should have a VERSION constant" do
5
- ValueStruct.const_get('VERSION').should_not be_empty
6
- end
7
-
8
- describe 'initialization' do
4
+ describe 'general behavior' do
9
5
  subject do
10
6
  ValueStruct.new(:x, :y)
11
7
  end
12
8
 
9
+ it "should have a VERSION constant" do
10
+ ValueStruct.const_get('VERSION').should_not be_empty
11
+ end
12
+
13
13
  it 'creates Class instances' do
14
14
  should be_instance_of Class
15
15
  end
@@ -37,12 +37,6 @@ describe ValueStruct do
37
37
  expect{ subject[:x] = 5 }.to raise_error(NoMethodError)
38
38
  end
39
39
 
40
- # it 'raises argument errors if not given the right number of arguments' do
41
- # lambda{
42
- # Point.new
43
- # }.should raise_error(ArgumentError, 'wrong number of arguments (0 for 2)')
44
- # end
45
-
46
40
  it 'can be inherited from to add methods' do
47
41
  class GraphPoint < ValueStruct.new(:x, :y)
48
42
  def inspect
@@ -86,9 +80,4 @@ describe ValueStruct do
86
80
  debugger
87
81
  end
88
82
  end
89
-
90
- # describe '#clone and #dup return the same object' do
91
- # it{ subject.object_id.should == subject.clone.object_id }
92
- # it{ subject.object_id.should == subject.dup.object_id }
93
- # end
94
83
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ValueStruct::ToH do
4
+ subject do
5
+ ValueStruct.new_with_mixins(:x, :y, [ValueStruct::ToH]).new(1,2)
6
+ end
7
+
8
+ its(:to_h) do
9
+ { x: 1, y: 2 }
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: value_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -191,6 +191,7 @@ files:
191
191
  - Rakefile
192
192
  - gemspec.yml
193
193
  - lib/value_struct.rb
194
+ - lib/value_struct/clone.rb
194
195
  - lib/value_struct/core.rb
195
196
  - lib/value_struct/dup_with_changes.rb
196
197
  - lib/value_struct/freeze.rb
@@ -198,8 +199,13 @@ files:
198
199
  - lib/value_struct/to_h.rb
199
200
  - lib/value_struct/version.rb
200
201
  - spec/benchmark.rb
202
+ - spec/clone_spec.rb
203
+ - spec/dup_with_changes_spec.rb
204
+ - spec/freeze_spec.rb
201
205
  - spec/spec_helper.rb
206
+ - spec/strict_arguments_spec.rb
202
207
  - spec/struct_value_spec.rb
208
+ - spec/to_h_spec.rb
203
209
  - value_struct.gemspec
204
210
  homepage: https://github.com/janlelis/value_struct
205
211
  licenses: