immutable_struct 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/immutable_struct.rb +12 -1
- metadata +21 -33
- data/.document +0 -5
- data/.gitignore +0 -21
- data/Rakefile +0 -48
- data/spec/immutable_struct_spec.rb +0 -47
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -13
data/lib/immutable_struct.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
class ImmutableStruct
|
2
|
-
VERSION = '1.0.
|
4
|
+
VERSION = '1.0.2'
|
3
5
|
|
4
6
|
def self.new(*attrs)
|
5
7
|
struct = Struct.new(*attrs)
|
6
8
|
make_immutable!(struct)
|
7
9
|
optionalize_constructor!(struct)
|
10
|
+
extend_dup!(struct)
|
8
11
|
struct
|
9
12
|
end
|
10
13
|
|
@@ -37,4 +40,12 @@ private
|
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
43
|
+
|
44
|
+
def self.extend_dup!(struct)
|
45
|
+
struct.class_eval do
|
46
|
+
def dup(overrides={})
|
47
|
+
self.class.new(to_h.merge(overrides))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
40
51
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immutable_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Theo Hultberg
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-09-26 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +25,9 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
28
|
segments:
|
31
|
-
-
|
32
|
-
|
33
|
-
- 9
|
34
|
-
version: 1.2.9
|
29
|
+
- 0
|
30
|
+
version: "0"
|
35
31
|
type: :development
|
36
32
|
version_requirements: *id001
|
37
33
|
- !ruby/object:Gem::Dependency
|
@@ -42,38 +38,31 @@ dependencies:
|
|
42
38
|
requirements:
|
43
39
|
- - ">="
|
44
40
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
41
|
segments:
|
47
42
|
- 0
|
48
43
|
version: "0"
|
49
44
|
type: :development
|
50
45
|
version_requirements: *id002
|
51
|
-
description:
|
52
|
-
email:
|
46
|
+
description: A version of Ruby's Struct class that creates classes whose instances are immutable. It works just as Struct, but there are no setters, and you can't use []=. As a bonus feature the constructor of classes inheriting from ImmutableStruct can take named parameters in the form of a hash.
|
47
|
+
email:
|
48
|
+
- theo@iconara.net
|
53
49
|
executables: []
|
54
50
|
|
55
51
|
extensions: []
|
56
52
|
|
57
|
-
extra_rdoc_files:
|
58
|
-
|
59
|
-
- README.mdown
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
60
55
|
files:
|
61
|
-
- .
|
62
|
-
- .gitignore
|
56
|
+
- lib/immutable_struct.rb
|
63
57
|
- LICENSE
|
64
58
|
- README.mdown
|
65
|
-
- Rakefile
|
66
|
-
- lib/immutable_struct.rb
|
67
|
-
- spec/immutable_struct_spec.rb
|
68
|
-
- spec/spec.opts
|
69
|
-
- spec/spec_helper.rb
|
70
59
|
has_rdoc: true
|
71
60
|
homepage: http://github.com/iconara/immutable_struct
|
72
61
|
licenses: []
|
73
62
|
|
74
63
|
post_install_message:
|
75
|
-
rdoc_options:
|
76
|
-
|
64
|
+
rdoc_options: []
|
65
|
+
|
77
66
|
require_paths:
|
78
67
|
- lib
|
79
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -81,7 +70,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
70
|
requirements:
|
82
71
|
- - ">="
|
83
72
|
- !ruby/object:Gem::Version
|
84
|
-
hash: 3
|
85
73
|
segments:
|
86
74
|
- 0
|
87
75
|
version: "0"
|
@@ -90,17 +78,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
78
|
requirements:
|
91
79
|
- - ">="
|
92
80
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 3
|
94
81
|
segments:
|
95
|
-
-
|
96
|
-
|
82
|
+
- 1
|
83
|
+
- 3
|
84
|
+
- 6
|
85
|
+
version: 1.3.6
|
97
86
|
requirements: []
|
98
87
|
|
99
|
-
rubyforge_project:
|
88
|
+
rubyforge_project: immutable_struct
|
100
89
|
rubygems_version: 1.3.7
|
101
90
|
signing_key:
|
102
91
|
specification_version: 3
|
103
|
-
summary:
|
104
|
-
test_files:
|
105
|
-
|
106
|
-
- spec/spec_helper.rb
|
92
|
+
summary: A version of Ruby's Struct class that creates classes whose instances are immutable
|
93
|
+
test_files: []
|
94
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'lib/immutable_struct'
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = 'immutable_struct'
|
10
|
-
gem.summary = %Q{An immutable version of Ruby's Struct class}
|
11
|
-
gem.description = %Q{An immutable implementation of Ruby's `Struct` class. It works just as Struct, but there are no setters, and you can't use `[]=`. As a bonus feature the constructor of classes inheriting from ImmutableStruct can take named parameters in the form of a hash.}
|
12
|
-
gem.email = 'theo@iconara.net'
|
13
|
-
gem.homepage = 'http://github.com/iconara/immutable_struct'
|
14
|
-
gem.authors = ['Theo Hultberg']
|
15
|
-
gem.add_development_dependency 'rspec', '>= 1.2.9'
|
16
|
-
gem.add_development_dependency 'yard', '>= 0'
|
17
|
-
gem.version = ImmutableStruct::VERSION
|
18
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
-
end
|
20
|
-
Jeweler::GemcutterTasks.new
|
21
|
-
rescue LoadError
|
22
|
-
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'spec/rake/spectask'
|
26
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
-
spec.libs << 'lib' << 'spec'
|
28
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
-
end
|
30
|
-
|
31
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
-
spec.libs << 'lib' << 'spec'
|
33
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
-
spec.rcov = true
|
35
|
-
end
|
36
|
-
|
37
|
-
task :spec => :check_dependencies
|
38
|
-
|
39
|
-
task :default => :spec
|
40
|
-
|
41
|
-
begin
|
42
|
-
require 'yard'
|
43
|
-
YARD::Rake::YardocTask.new
|
44
|
-
rescue LoadError
|
45
|
-
task :yardoc do
|
46
|
-
abort 'YARD is not available. In order to run yardoc, you must: sudo gem install yard'
|
47
|
-
end
|
48
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
|
4
|
-
describe ImmutableStruct do
|
5
|
-
|
6
|
-
class ImmutableItem < ImmutableStruct.new(:a, :b); end
|
7
|
-
|
8
|
-
it 'can be used as a superclass just like Struct' do
|
9
|
-
obj = ImmutableItem.new(1, 2)
|
10
|
-
obj.a.should == 1
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'creates no setters' do
|
14
|
-
obj = ImmutableItem.new(1, 2)
|
15
|
-
running { obj.a = 3 }.should raise_error
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'does not allow [] to be used to mutate the instance' do
|
19
|
-
obj = ImmutableItem.new(1, 2)
|
20
|
-
running { obj[:a] = 3 }.should raise_error
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'creates a constructor that works like the one Struct creates' do
|
24
|
-
obj = ImmutableItem.new(1, 2)
|
25
|
-
obj.a.should == 1
|
26
|
-
obj.b.should == 2
|
27
|
-
obj = ImmutableItem.new(1)
|
28
|
-
obj.a.should == 1
|
29
|
-
obj.b.should == nil
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'creates a constructor that takes a hash' do
|
33
|
-
obj = ImmutableItem.new(:a => 1, :b => 2)
|
34
|
-
obj.a.should == 1
|
35
|
-
obj.b.should == 2
|
36
|
-
obj = ImmutableItem.new(:b => 2)
|
37
|
-
obj.a.should == nil
|
38
|
-
obj.b.should == 2
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'adds #to_h that returns a hash representation of the object' do
|
42
|
-
obj = ImmutableItem.new(:a => 1, :b => 2)
|
43
|
-
obj.to_h.should have_key(:a)
|
44
|
-
obj.to_h.should have_key(:b)
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/spec/spec_helper.rb
DELETED