finer_struct 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/finer_struct/named.rb +5 -9
- data/lib/finer_struct/version.rb +1 -1
- data/spec/finer_struct/immutable_spec.rb +1 -1
- data/spec/finer_struct/mutable_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb07bc226c4369e3ea51c098110c69601058731
|
4
|
+
data.tar.gz: 19913677ea5bffc3174d3730587bc29971525499
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f06fa6b4e01a075fe2b2377d7e5df0c5b877a0ea01df1c5d1e223d14effd8670540140f3ad663f0601e9ca04e6638d7353508103b54c3ec29021f4c87661241b
|
7
|
+
data.tar.gz: f001d24b97f51e1c7f61a6eab3db868c2c151c15155ada1130e4870dea11002f72133a49f83621163912593eee1d8db1a51a993468411850e266e788593949fa
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ Immutable structs can't have their attributes changed after creation.
|
|
42
42
|
|
43
43
|
#### Named immutable structs
|
44
44
|
|
45
|
-
class MyStruct < FinerStruct::Immutable(:a, :b)
|
45
|
+
class MyStruct < FinerStruct::Immutable(:a, :b); end
|
46
46
|
struct = MyStruct.new(a: 1, b: 2)
|
47
47
|
|
48
48
|
MyStruct.new(a: 1, b: 2, c: 3) # Exception!
|
@@ -60,7 +60,7 @@ Mutable structs let you assign attributes at any time.
|
|
60
60
|
|
61
61
|
#### Named mutable structs
|
62
62
|
|
63
|
-
class MyStruct < FinerStruct::Mutable(:a, :b)
|
63
|
+
class MyStruct < FinerStruct::Mutable(:a, :b); end
|
64
64
|
struct = MyStruct.new(a: 1, b: 2)
|
65
65
|
|
66
66
|
## Contributing
|
data/lib/finer_struct/named.rb
CHANGED
@@ -3,18 +3,14 @@ module FinerStruct
|
|
3
3
|
module Named
|
4
4
|
def self.build_class(attribute_names, &block)
|
5
5
|
Class.new do
|
6
|
-
|
7
|
-
|
8
|
-
class << self
|
9
|
-
attr_reader :attribute_names
|
10
|
-
end
|
6
|
+
define_method(:attribute_names, -> { attribute_names })
|
11
7
|
|
12
8
|
def initialize(attributes = {})
|
13
|
-
attributes.each_pair do |
|
14
|
-
unless
|
15
|
-
raise(ArgumentError, "no such attribute: #{
|
9
|
+
attributes.each_pair do |name, value|
|
10
|
+
unless attribute_names.include?(name)
|
11
|
+
raise(ArgumentError, "no such attribute: #{name}")
|
16
12
|
end
|
17
|
-
instance_variable_set("@#{
|
13
|
+
instance_variable_set("@#{name}", value)
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
data/lib/finer_struct/version.rb
CHANGED
@@ -18,7 +18,7 @@ module FinerStruct
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "a named immutable struct" do
|
21
|
-
let(:klass) { FinerStruct::Immutable(:a, :b) }
|
21
|
+
let(:klass) { Class.new(FinerStruct::Immutable(:a, :b)) }
|
22
22
|
subject { klass.new(a: 1, b: 2) }
|
23
23
|
|
24
24
|
it_behaves_like "an immutable struct"
|