finer_struct 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3491e5caa09c1057794a39b3ba8f0a95b2744229
4
- data.tar.gz: ea0c2d42894da066df1d2128385be6b8ab2ecf82
3
+ metadata.gz: 8fb07bc226c4369e3ea51c098110c69601058731
4
+ data.tar.gz: 19913677ea5bffc3174d3730587bc29971525499
5
5
  SHA512:
6
- metadata.gz: 61eee0dcdc83567e87785bbf9c6a6b513ca1770c4d21189c7e793442afc0bbbd0d22713c9fcbde3b51816c9106fa470a830986482740dc6137cfacb508308835
7
- data.tar.gz: 08cf4a47fb86f206f0915568830e2678ec7321923ad78814866860824a9211310e30a558ff97f5d54420e22a7757fff620a60c2003e988ed208e9874551d08bd
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
@@ -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
- @attribute_names = attribute_names
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 |key, value|
14
- unless self.class.attribute_names.include?(key)
15
- raise(ArgumentError, "no such attribute: #{key}")
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("@#{key}", value)
13
+ instance_variable_set("@#{name}", value)
18
14
  end
19
15
  end
20
16
 
@@ -1,3 +1,3 @@
1
1
  module FinerStruct
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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"
@@ -19,7 +19,7 @@ module FinerStruct
19
19
  end
20
20
 
21
21
  describe "a named mutable struct" do
22
- let(:klass) { FinerStruct::Mutable(:a, :b) }
22
+ let(:klass) { Class.new(FinerStruct::Mutable(:a, :b)) }
23
23
  subject { klass.new(a: 1, b: 2) }
24
24
 
25
25
  it_behaves_like "a mutable struct"
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Yandell