striuct 0.4.4.1 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 746edaaaf527160fde69fb136722ff8861375af7
4
- data.tar.gz: 17062017c2bec73985602a5c4069ffec47acc3f6
3
+ metadata.gz: a30f4e23f85f0d1dfe93361680098c4392fa5310
4
+ data.tar.gz: eebe3b499e546f79818ff526a526dfd254b79412
5
5
  SHA512:
6
- metadata.gz: 7c3897a36c553fcc2f760581e7b844cb81256e08b774efc4d81ca7ae6d24a811fbb2431a842acd24cd69bafdc045c58ba3ea46674b089eaf639f5acef7a89482
7
- data.tar.gz: 57a64de8a4faa2a740856f770f121f9ade2d924d3a2f99625d2ed3dd369b4f7ddf4a23d8d3e00f2485c9fc82e12dae8038cd37a6df453627c383486a1bd6c6af
6
+ metadata.gz: b79df0bcae7d599d530193891fafed7831507b09c4b77b4841eb1fdb79c7454928cadcd5585b58582b378e72c7a944cfb0ca8a6b47ee436bf5ff3535e4413a02
7
+ data.tar.gz: 8b40078d94fe1c120e98885a1861359fdc1d0fd948f2ec528e27fcc8c4a602b73987af3bb6da8232e325b1519401371472bfeaa9598282dd4d73549474abd4ef
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ rvm:
5
5
  - 2.2
6
6
  - 2.1
7
7
  - 2.0
8
- - 1.9.3
9
8
  - ruby-head
10
9
  - rbx-2
11
10
  - jruby-head
data/README.md CHANGED
@@ -3,6 +3,7 @@ striuct
3
3
 
4
4
  [![Build Status](https://secure.travis-ci.org/kachick/striuct.png)](http://travis-ci.org/kachick/striuct)
5
5
  [![Gem Version](https://badge.fury.io/rb/striuct.png)](http://badge.fury.io/rb/striuct)
6
+ [![Dependency Status](https://gemnasium.com/kachick/striuct.svg)](https://gemnasium.com/kachick/striuct)
6
7
 
7
8
  Description
8
9
  -----------
@@ -113,7 +114,7 @@ UseMustOption.new #=> InvalidOperationError "`foo` require a value under `must`
113
114
  Requirements
114
115
  -------------
115
116
 
116
- * Ruby - [1.9.2 or later](http://travis-ci.org/#!/kachick/striuct)
117
+ * Ruby - [2.0 or later](http://travis-ci.org/#!/kachick/striuct)
117
118
 
118
119
  Install
119
120
  -------
@@ -125,10 +126,10 @@ gem install striuct
125
126
  Link
126
127
  ----
127
128
 
128
- * [code](https://github.com/kachick/striuct)
129
- * [wiki](https://github.com/kachick/striuct/wiki)
130
- * [API](http://kachick.github.com/striuct/yard/frames.html)
131
- * [issues](https://github.com/kachick/striuct/issues)
129
+ * [Code](https://github.com/kachick/striuct)
130
+ * [Wiki](https://github.com/kachick/striuct/wiki)
131
+ * [API](http://www.rubydoc.info/github/kachick/striuct)
132
+ * [Issues](https://github.com/kachick/striuct/issues)
132
133
  * [CI](http://travis-ci.org/#!/kachick/striuct)
133
134
  * [gem](https://rubygems.org/gems/striuct)
134
135
 
@@ -137,4 +138,4 @@ License
137
138
 
138
139
  The MIT X11 License
139
140
  Copyright (c) 2011 Kenichi Kamiya
140
- See MIT-LICENSE for further details.
141
+ See MIT-LICENSE for further details.
@@ -7,7 +7,7 @@ class Striuct; module ClassMethods
7
7
  # @yieldreturn [Class] self
8
8
  # @return [Enumerator]
9
9
  def each_autonym
10
- return to_enum(__callee__) unless block_given?
10
+ return to_enum(__callee__) { size } unless block_given?
11
11
 
12
12
  @autonyms.each{|autonym|yield autonym}
13
13
  self
@@ -20,7 +20,7 @@ class Striuct; module ClassMethods
20
20
  # @yieldreturn [Class] self
21
21
  # @return [Enumerator]
22
22
  def each_index
23
- return to_enum(__callee__) unless block_given?
23
+ return to_enum(__callee__) { size } unless block_given?
24
24
 
25
25
  @autonyms.each_index{|index|yield index}
26
26
  self
@@ -32,7 +32,7 @@ class Striuct; module ClassMethods
32
32
  # @yieldreturn [Class] self
33
33
  # @return [Enumerator]
34
34
  def each_autonym_with_index
35
- return to_enum(__callee__) unless block_given?
35
+ return to_enum(__callee__) { size } unless block_given?
36
36
 
37
37
  @autonyms.each_with_index{|autonym, index|yield autonym, index}
38
38
  self
@@ -42,4 +42,4 @@ class Striuct; module ClassMethods
42
42
 
43
43
  # @endgroup
44
44
 
45
- end; end
45
+ end; end
@@ -7,7 +7,7 @@ class Striuct; module InstanceMethods
7
7
  # @yieldreturn [self]
8
8
  # @return [Enumerator]
9
9
  def each_autonym(&block)
10
- return to_enum(__callee__) unless block_given?
10
+ return to_enum(__callee__) { self.class.size } unless block_given?
11
11
 
12
12
  self.class.each_autonym(&block)
13
13
  self
@@ -21,7 +21,7 @@ class Striuct; module InstanceMethods
21
21
  # @yieldreturn [self]
22
22
  # @return [Enumerator]
23
23
  def each_value
24
- return to_enum(__callee__) unless block_given?
24
+ return to_enum(__callee__) { self.class.size } unless block_given?
25
25
 
26
26
  each_autonym{|autonym|yield _get(autonym)}
27
27
  end
@@ -36,7 +36,7 @@ class Striuct; module InstanceMethods
36
36
  # @see #each_autonym
37
37
  # @see #each_value
38
38
  def each_pair
39
- return to_enum(__callee__) unless block_given?
39
+ return to_enum(__callee__) { self.class.size } unless block_given?
40
40
 
41
41
  each_autonym{|autonym|yield autonym, _get(autonym)}
42
42
  end
@@ -46,7 +46,7 @@ class Striuct; module InstanceMethods
46
46
  # @yieldreturn [self]
47
47
  # @return [Enumerator]
48
48
  def each_index
49
- return to_enum(__callee__) unless block_given?
49
+ return to_enum(__callee__) { self.class.size } unless block_given?
50
50
 
51
51
  self.class.each_index{|index|yield index}
52
52
  self
@@ -58,7 +58,7 @@ class Striuct; module InstanceMethods
58
58
  # @yieldreturn [self]
59
59
  # @return [Enumerator]
60
60
  def each_autonym_with_index
61
- return to_enum(__callee__) unless block_given?
61
+ return to_enum(__callee__) { self.class.size } unless block_given?
62
62
 
63
63
  self.class.each_autonym_with_index{|autonym, index|yield autonym, index}
64
64
  self
@@ -71,7 +71,7 @@ class Striuct; module InstanceMethods
71
71
  # @yieldreturn [self]
72
72
  # @return [Enumerator]
73
73
  def each_value_with_index
74
- return to_enum(__callee__) unless block_given?
74
+ return to_enum(__callee__) { self.class.size } unless block_given?
75
75
 
76
76
  each_value.with_index{|value, index|yield value, index}
77
77
  end
@@ -84,7 +84,7 @@ class Striuct; module InstanceMethods
84
84
  # @yieldreturn [self]
85
85
  # @return [Enumerator]
86
86
  def each_pair_with_index
87
- return to_enum(__callee__) unless block_given?
87
+ return to_enum(__callee__) { self.class.size } unless block_given?
88
88
 
89
89
  index = 0
90
90
  each_pair do |autonym, value|
@@ -95,4 +95,4 @@ class Striuct; module InstanceMethods
95
95
 
96
96
  # @endgroup
97
97
 
98
- end; end
98
+ end; end
@@ -23,6 +23,23 @@ class Striuct; module InstanceMethods
23
23
  }
24
24
  end
25
25
 
26
+ # @return [Array]
27
+ # @raise [ArgumentError] if the keys contains an unmacthed
28
+ # key and no block is given
29
+ def fetch_values(*_keys, &block)
30
+ _keys.map {|key|
31
+ if has_key? key
32
+ fetch_by_key(key)
33
+ else
34
+ if block_given?
35
+ block.call
36
+ else
37
+ raise ArgumentError, "`#{key}' is not matched"
38
+ end
39
+ end
40
+ }
41
+ end
42
+
26
43
  # @return [self]
27
44
  def replace_values(*values)
28
45
  unless values.size <= size
@@ -38,4 +55,4 @@ class Striuct; module InstanceMethods
38
55
 
39
56
  # @endgroup
40
57
 
41
- end; end
58
+ end; end
data/striuct.gemspec CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |gem|
17
17
  gem.homepage = "https://github.com/kachick/#{lib_name}"
18
18
  gem.license = 'MIT'
19
19
  gem.name = lib_name.dup
20
- gem.version = '0.4.4.1'
20
+ gem.version = '0.5.0'
21
21
 
22
- gem.required_ruby_version = '>= 1.9.3'
22
+ gem.required_ruby_version = '>= 2.0'
23
23
 
24
24
  gem.add_runtime_dependency 'validation', '~> 0.0.7'
25
25
  gem.add_runtime_dependency 'optionalargument', '~> 0.1'
@@ -25,6 +25,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
25
25
 
26
26
  enum = reciever.public_send(callee)
27
27
  assert_instance_of Enumerator, enum
28
+ assert_equal 2, enum.size
28
29
  assert_same :foo, enum.next
29
30
  assert_same :bar, enum.next
30
31
  assert_raises StopIteration do
@@ -41,6 +42,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
41
42
 
42
43
  enum = reciever.public_send(callee)
43
44
  assert_instance_of Enumerator, enum
45
+ assert_equal 2, enum.size
44
46
  assert_same 0, enum.next
45
47
  assert_same 1, enum.next
46
48
  assert_raises StopIteration do
@@ -57,6 +59,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
57
59
 
58
60
  enum = reciever.public_send(callee)
59
61
  assert_instance_of Enumerator, enum
62
+ assert_equal 2, enum.size
60
63
  assert_equal [:foo, 0], enum.next
61
64
  assert_equal [:bar, 1], enum.next
62
65
  assert_raises StopIteration do
@@ -73,6 +76,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
73
76
 
74
77
  enum = reciever.public_send(callee)
75
78
  assert_instance_of Enumerator, enum
79
+ assert_equal 2, enum.size
76
80
  assert_same FOO, enum.next
77
81
  assert_same BAR, enum.next
78
82
  assert_raises StopIteration do
@@ -89,6 +93,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
89
93
 
90
94
  enum = reciever.public_send(callee)
91
95
  assert_instance_of Enumerator, enum
96
+ assert_equal 2, enum.size
92
97
  assert_equal [FOO, 0], ret = enum.next
93
98
  assert_same FOO, ret.first
94
99
  assert_equal [BAR, 1], ret = enum.next
@@ -107,6 +112,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
107
112
 
108
113
  enum = reciever.public_send(callee)
109
114
  assert_instance_of Enumerator, enum
115
+ assert_equal 2, enum.size
110
116
  assert_equal [:foo, FOO], ret = enum.next
111
117
  assert_same FOO, ret.last
112
118
  assert_equal [:bar, BAR], ret = enum.next
@@ -125,6 +131,7 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
125
131
 
126
132
  enum = reciever.public_send(callee)
127
133
  assert_instance_of Enumerator, enum
134
+ assert_equal 2, enum.size
128
135
  assert_equal [:foo, FOO, 0], ret = enum.next
129
136
  assert_same FOO, ret[1]
130
137
  assert_equal [:bar, BAR, 1], ret = enum.next
@@ -134,6 +141,19 @@ class Test_Striuct_Subclass_Enum < Test::Unit::TestCase
134
141
  end
135
142
  end
136
143
  end
144
+
145
+ def test_modified_members_enum_size
146
+ klass = Striuct.new do
147
+ member :foo
148
+ end
149
+ cenum = klass.each_autonym
150
+ ienum = klass.new.each_autonym
151
+ assert_equal 1, cenum.size
152
+ assert_equal 1, ienum.size
153
+ klass.send :member, :bar
154
+ assert_equal 2, cenum.size
155
+ assert_equal 2, ienum.size
156
+ end
137
157
  end
138
158
 
139
- end
159
+ end
@@ -29,4 +29,15 @@ class Test_Striuct_Subclass_Instance_Basic < Test::Unit::TestCase
29
29
  assert_equal(@user.values_at(4, 0, (2..4)), [30, 9999, 'yamada', 'Tokyo Japan', 30])
30
30
  end
31
31
 
32
+ def test_fetch_values
33
+ assert_equal(@user.fetch_values(:id, 4, :id), [9999, 30, 9999])
34
+ assert_equal(@user.fetch_values, [])
35
+
36
+ assert_raise ArgumentError do
37
+ @user.fetch_values :id, 5, :id
38
+ end
39
+
40
+ assert_equal(@user.fetch_values(:id, 5, :id) { :substitute }, [9999, :substitute, 9999])
41
+ end
42
+
32
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: striuct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
@@ -246,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - ">="
248
248
  - !ruby/object:Gem::Version
249
- version: 1.9.3
249
+ version: '2.0'
250
250
  required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  requirements:
252
252
  - - ">="
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  requirements: []
256
256
  rubyforge_project:
257
- rubygems_version: 2.4.5
257
+ rubygems_version: 2.4.8
258
258
  signing_key:
259
259
  specification_version: 4
260
260
  summary: Struct++ library. --- Validatable, Inheritable, Member Aliasing, Conflict