better_struct 0.3.0 → 0.3.1

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: 769d8c773ce3b173db61b643690f593dfb5fecf3
4
- data.tar.gz: 7647a81cd6a1b7b25a7f23dad153e3a5ebb3dfa4
3
+ metadata.gz: c3274ecdeb9fbdf35c3cd30b64eb069d16d854ca
4
+ data.tar.gz: 25e17ddafdb1ebb12860da133b79195143eda353
5
5
  SHA512:
6
- metadata.gz: 1dd5b1022f097f919d9b65883301950f643bda6d145cc6eee14e32ef3c8c8c0686b90f888193415ea3b5f1110a755227c152dbf8adb8d227c3dd4fa53cde54ce
7
- data.tar.gz: d4fd8c5ed520589ee4d4981dbfb5dddfa3573202f629c8b483bec691c9cfb241b760b75c27f453f483fb461c67d1e892857c15da3832a7d624b67778f269f60e
6
+ metadata.gz: a3272eaba0944b3ff497d043b1b69b66f8df28f2bce438e85144b3fa27107b1563ee057ec2c5e18d3d89515564fa1e4e6d0629cab4b50e7e8fa1cf818401561b
7
+ data.tar.gz: ccfa4f37aac90379c96218952cb8c9ca57063f2894530791206f81f8387d7d69fb2ddcff32c18f6f32cda0c26ba07ee73d70c9fff58181ae5b0f4f36733d0fc0
@@ -35,7 +35,7 @@ private
35
35
  @__defined_methods = {}
36
36
 
37
37
  if value && value.respond_to?(:each_pair)
38
- value.each_pair { |key, v| @__defined_methods[__methodize(key)] = v }
38
+ value.each_pair { |k, v| @__defined_methods[__methodize(k)] = v }
39
39
  end
40
40
  end
41
41
 
@@ -29,7 +29,9 @@ private
29
29
  end
30
30
 
31
31
  def __methodized?(string)
32
- !string =~ BEFORE_FIRST_DIGIT_OR_NON_UNDERSCORED_REGEXP && !string =~ UNDERSCORE_DUPLICATES_REGEXP
32
+ return false if string =~ BEFORE_FIRST_DIGIT_OR_NON_UNDERSCORED_REGEXP
33
+ return false if string =~ UNDERSCORE_DUPLICATES_REGEXP
34
+ true
33
35
  end
34
36
 
35
37
  def __transliterate!(string)
@@ -1,3 +1,3 @@
1
1
  class BetterStruct
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.3.1".freeze
3
3
  end
@@ -78,6 +78,39 @@ module BetterStructTest
78
78
  assert better_struct.map { |i| i * i * 2 }.value == [2, 8, 18]
79
79
  end
80
80
 
81
+ def test_new_assignment
82
+ better_struct = BetterStruct.new
83
+
84
+ better_struct.head = [1, 2, 3]
85
+
86
+ assert better_struct.head == BetterStruct.new([1, 2, 3])
87
+ end
88
+
89
+ def test_input_args_immutability
90
+ better_struct = BetterStruct.new(head: [1, 2, 3])
91
+ tail = [4, 5, 6]
92
+
93
+ better_struct.head.concat(tail)
94
+
95
+ assert better_struct.head == BetterStruct.new([1, 2, 3, 4, 5, 6])
96
+ assert tail == [4, 5, 6]
97
+ end
98
+ end
99
+
100
+ class Methodize < Minitest::Test
101
+ def test_methodize_checking
102
+ better_struct = BetterStruct.new(not__undescore: 1)
103
+
104
+ assert better_struct.not__undescore.value == nil
105
+ assert better_struct.not_undescore.value == 1
106
+ end
107
+
108
+ def test_methodizing
109
+ better_struct = BetterStruct.new("FooBar foo_bar": 1)
110
+
111
+ assert better_struct.foo_bar_foo_bar.value == 1
112
+ end
113
+
81
114
  def test_methods_underscoring
82
115
  better_struct = BetterStruct.new({ "! CHAMPION !" => 1 })
83
116
 
@@ -101,23 +134,5 @@ module BetterStructTest
101
134
 
102
135
  assert better_struct.titulo.value == 1
103
136
  end
104
-
105
- def test_new_assignment
106
- better_struct = BetterStruct.new
107
-
108
- better_struct.head = [1, 2, 3]
109
-
110
- assert better_struct.head == BetterStruct.new([1, 2, 3])
111
- end
112
-
113
- def test_input_args_immutability
114
- better_struct = BetterStruct.new(head: [1, 2, 3])
115
- tail = [4, 5, 6]
116
-
117
- better_struct.head.concat(tail)
118
-
119
- assert better_struct.head == BetterStruct.new([1, 2, 3, 4, 5, 6])
120
- assert tail == [4, 5, 6]
121
- end
122
137
  end
123
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li