finer_struct 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/finer_struct/immutable.rb +3 -16
- data/lib/finer_struct/mutable.rb +2 -16
- data/lib/finer_struct/named.rb +26 -0
- data/lib/finer_struct/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3491e5caa09c1057794a39b3ba8f0a95b2744229
|
4
|
+
data.tar.gz: ea0c2d42894da066df1d2128385be6b8ab2ecf82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61eee0dcdc83567e87785bbf9c6a6b513ca1770c4d21189c7e793442afc0bbbd0d22713c9fcbde3b51816c9106fa470a830986482740dc6137cfacb508308835
|
7
|
+
data.tar.gz: 08cf4a47fb86f206f0915568830e2678ec7321923ad78814866860824a9211310e30a558ff97f5d54420e22a7757fff620a60c2003e988ed208e9874551d08bd
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'finer_struct/named'
|
2
|
+
|
1
3
|
module FinerStruct
|
2
4
|
|
3
5
|
class Immutable
|
@@ -15,23 +17,8 @@ module FinerStruct
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.Immutable(*attribute_names)
|
18
|
-
|
19
|
-
@attribute_names = attribute_names
|
20
|
-
|
21
|
-
class << self
|
22
|
-
attr_reader :attribute_names
|
23
|
-
end
|
24
|
-
|
20
|
+
Named.build_class(attribute_names) do
|
25
21
|
attr_reader(*attribute_names)
|
26
|
-
|
27
|
-
def initialize(attributes = {})
|
28
|
-
attributes.each_pair do |key, value|
|
29
|
-
unless self.class.attribute_names.include?(key)
|
30
|
-
raise(ArgumentError, "no such attribute: #{key}")
|
31
|
-
end
|
32
|
-
instance_variable_set("@#{key}", value)
|
33
|
-
end
|
34
|
-
end
|
35
22
|
end
|
36
23
|
end
|
37
24
|
|
data/lib/finer_struct/mutable.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'finer_struct/immutable'
|
2
|
+
require 'finer_struct/named'
|
2
3
|
|
3
4
|
module FinerStruct
|
4
5
|
|
@@ -23,23 +24,8 @@ module FinerStruct
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.Mutable(*attribute_names)
|
26
|
-
|
27
|
-
@attribute_names = attribute_names
|
28
|
-
|
29
|
-
class << self
|
30
|
-
attr_reader :attribute_names
|
31
|
-
end
|
32
|
-
|
27
|
+
Named.build_class(attribute_names) do
|
33
28
|
attr_accessor(*attribute_names)
|
34
|
-
|
35
|
-
def initialize(attributes = {})
|
36
|
-
attributes.each_pair do |key, value|
|
37
|
-
unless self.class.attribute_names.include?(key)
|
38
|
-
raise(ArgumentError, "no such attribute: #{key}")
|
39
|
-
end
|
40
|
-
instance_variable_set("@#{key}", value)
|
41
|
-
end
|
42
|
-
end
|
43
29
|
end
|
44
30
|
end
|
45
31
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module FinerStruct
|
2
|
+
|
3
|
+
module Named
|
4
|
+
def self.build_class(attribute_names, &block)
|
5
|
+
Class.new do
|
6
|
+
@attribute_names = attribute_names
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_reader :attribute_names
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
attributes.each_pair do |key, value|
|
14
|
+
unless self.class.attribute_names.include?(key)
|
15
|
+
raise(ArgumentError, "no such attribute: #{key}")
|
16
|
+
end
|
17
|
+
instance_variable_set("@#{key}", value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
instance_eval(&block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/finer_struct/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finer_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Yandell
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/finer_struct.rb
|
69
69
|
- lib/finer_struct/immutable.rb
|
70
70
|
- lib/finer_struct/mutable.rb
|
71
|
+
- lib/finer_struct/named.rb
|
71
72
|
- lib/finer_struct/version.rb
|
72
73
|
- spec/finer_struct/immutable_spec.rb
|
73
74
|
- spec/finer_struct/mutable_spec.rb
|