struct-alias_member 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of struct-alias_member might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8729ce06b62e961a18c5c3f8d91becb2e98cafaf443be309f1ec83f51faf51a0
4
+ data.tar.gz: 7c5bfdd59450c0b2e17cb1484a92b02c38a949ca53aa5b986b79705b277e7126
5
+ SHA512:
6
+ metadata.gz: eeb923b8b4375c7bc0fc428db590ccdaff195bbfc0f25859733ce828c770893524a48451c7b85332ca4bdbc4e4812f37112fc57bb3190bab918d16e2ea843bc9
7
+ data.tar.gz: 4d37991f7f98a821c31abc6c23f278d1abca19926e3495b2c2dcb255549758cea79c28d8da0ee80d5b03add2e4f385cd85495c6e38e36c9b7cc2abddaa629d5d
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ *#*
30
+ .redcar
31
+
32
+ # other
33
+ *.lock
34
+ .rbx
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.6
6
+ - 2.5
7
+ - rbx-3
8
+ - jruby-head
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: rbx-3
14
+ - rvm: jruby-head
15
+
16
+ before_install:
17
+ - gem install bundler
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --readme README.md lib/**/*.rb - MIT-LICENSE
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # coding: us-ascii
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rake'
13
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X11 License)
2
+
3
+ Copyright (c) 2012 Kenichi Kamiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ struct-alias_member
2
+ ====================
3
+
4
+ [![Build Status](https://secure.travis-ci.org/kachick/struct-alias_member.png)](http://travis-ci.org/kachick/struct-alias_member)
5
+ [![Gem Version](https://badge.fury.io/rb/struct-alias_member.png)](http://badge.fury.io/rb/struct-alias_member)
6
+
7
+ Description
8
+ ------------
9
+
10
+ Struct will be able to alias the members name.
11
+
12
+ Usage
13
+ ------
14
+
15
+ ### Overview
16
+
17
+ ```ruby
18
+ require 'struct/alias_member'
19
+
20
+ BankAccount = Struct.new :name, :balance do
21
+ alias_member :money, :balance
22
+ end
23
+
24
+ ac = BankAccount.new 'John', 100
25
+ ac.money #=> 100
26
+ ac[:money] #=> 100
27
+ ac[:money] = 999
28
+ ac.balance #=> 999
29
+ ac.member? :money #=> true
30
+ ac.aliases #=> {:money=>:balance}
31
+ ```
32
+
33
+ Requirements
34
+ ------------
35
+
36
+ * [Ruby 2.5 or later](http://travis-ci.org/#!/kachick/struct-alias_member)
37
+
38
+ Install
39
+ -------
40
+
41
+ ```bash
42
+ $ gem install struct-alias_member
43
+ ```
44
+
45
+ Link
46
+ ----
47
+
48
+ * [Home](http://kachick.github.com/struct-alias_member)
49
+ * [code](https://github.com/kachick/struct-alias_member)
50
+ * [API](http://kachick.github.com/struct-alias_member/yard/frames.html)
51
+ * [issues](https://github.com/kachick/struct-alias_member/issues)
52
+ * [CI](http://travis-ci.org/#!/kachick/struct-alias_member)
53
+ * [gem](https://rubygems.org/gems/struct-alias_member)
54
+
55
+ License
56
+ -------
57
+
58
+ The MIT X11 License
59
+ Copyright (c) 2012 Kenichi Kamiya
60
+ See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ # coding: us-ascii
3
+
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rake/testtask'
7
+
8
+ task default: [:test]
9
+
10
+ Rake::TestTask.new do |tt|
11
+ tt.verbose = true
12
+ tt.warning = true
13
+ end
data/example/README.rb ADDED
@@ -0,0 +1,17 @@
1
+ # coding: us-ascii
2
+
3
+ $VERBOSE = true
4
+
5
+ require_relative '../lib/struct/alias_member'
6
+
7
+ BankAccount = Struct.new :name, :balance do
8
+ alias_member :money, :balance
9
+ end
10
+
11
+ ac = BankAccount.new 'John', 100
12
+ p ac.money #=> 100
13
+ p ac[:money] #=> 100
14
+ p ac[:money] = 999
15
+ p ac.balance #=> 999
16
+ p ac.member? :money #=> true
17
+ p ac.aliases #=> {:money=>:balance}
@@ -0,0 +1,8 @@
1
+ # coding: us-ascii
2
+ # Copyright (c) 2012 Kenichi Kamiya
3
+
4
+ require_relative 'alias_member/version'
5
+ require_relative 'alias_member/classmethods'
6
+ require_relative 'alias_member/subclassclassmethods'
7
+ require_relative 'alias_member/subclassinstancemethods'
8
+ require_relative 'alias_member/core_ext'
@@ -0,0 +1,21 @@
1
+ # coding: us-ascii
2
+
3
+ class Struct; module Alias_Member
4
+
5
+ module ClassMethods
6
+
7
+ private
8
+
9
+ def inherited(cls)
10
+ super
11
+
12
+ cls.class_eval do
13
+ extend Alias_Member::SubclassClassMethods
14
+ include Alias_Member::SubclassInstanceMethods
15
+ @aliases = {}
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end; end
@@ -0,0 +1,7 @@
1
+ # coding: us-ascii
2
+
3
+ class Struct
4
+
5
+ extend Alias_Member::ClassMethods
6
+
7
+ end
@@ -0,0 +1,53 @@
1
+ # coding: us-ascii
2
+
3
+ class Struct; module Alias_Member
4
+
5
+ module SubclassClassMethods
6
+
7
+ # @return [Hash] aliasA => autonymX, aliasB => autonymY
8
+ def aliases
9
+ @aliases.dup
10
+ end
11
+
12
+ # @param [Symbol, String, #to_sym] name
13
+ # @return [Symbol]
14
+ def autonym_for_name(name)
15
+ name = name.to_sym
16
+
17
+ members.include?(name) ? name : @aliases.fetch(name)
18
+ end
19
+
20
+
21
+ # @param [Symbol, String, #to_sym, Integer, #to_int] key
22
+ # @return [Symbol]
23
+ def autonym_for_key(key)
24
+ case key
25
+ when ->v{v.respond_to? :to_sym}
26
+ autonym_for_name key.to_sym
27
+ when ->v{v.respond_to? :to_int}
28
+ members.fetch key.to_int
29
+ else
30
+ raise TypeError
31
+ end
32
+ end
33
+
34
+ # @param [Symbol, String, #to_sym] aliased
35
+ # @param [Symbol, String, #to_sym] autonym
36
+ # @return [Module]
37
+ def alias_member(aliased, autonym)
38
+ class_eval do
39
+ aliased, autonym = aliased.to_sym, autonym.to_sym
40
+ if @aliases.has_key?(aliased) or members.include?(aliased)
41
+ raise Alias_Member::ArleadyDefinedError
42
+ end
43
+
44
+ @aliases[aliased] = autonym
45
+
46
+ alias_method aliased, autonym
47
+ alias_method :"#{aliased}=", :"#{autonym}="
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end; end
@@ -0,0 +1,33 @@
1
+ # coding: us-ascii
2
+
3
+ class Struct; module Alias_Member
4
+
5
+ module SubclassInstanceMethods
6
+
7
+ # @param [Symbol, String, #to_sym, Integer, #to_int] key
8
+ def [](key)
9
+ super self.class.autonym_for_key(key)
10
+ end
11
+
12
+ # @param [Symbol, String, #to_sym, Integer, #to_int] key
13
+ # @return value
14
+ def []=(key, value)
15
+ super self.class.autonym_for_key(key), value
16
+ end
17
+
18
+ # @see [ClassMethods#aliases]
19
+ # @return [Hash]
20
+ def aliases
21
+ self.class.aliases
22
+ end
23
+
24
+ # @param [Symbol, String, #to_sym] name
25
+ def member?(name)
26
+ name = name.to_sym
27
+
28
+ members.include?(name) || aliases.has_key?(name)
29
+ end
30
+
31
+ end
32
+
33
+ end; end
@@ -0,0 +1,11 @@
1
+ # coding: us-ascii
2
+
3
+ class Struct
4
+
5
+ module Alias_Member
6
+
7
+ VERSION = '0.1.0'.freeze
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,34 @@
1
+ # coding: us-ascii
2
+
3
+ require File.expand_path('../lib/struct/alias_member/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ # specific
7
+
8
+ gem.description = %q{Struct will be able to alias the members name.}
9
+ gem.summary = gem.description.dup
10
+ gem.homepage = 'http://kachick.github.com/struct-alias_member'
11
+ gem.license = 'MIT'
12
+
13
+ gem.name = 'struct-alias_member'
14
+ gem.version = Struct::Alias_Member::VERSION.dup
15
+
16
+ gem.add_development_dependency 'test-declare', '~> 0.0.3'
17
+ gem.add_development_dependency 'yard', '>= 0.9.20', '< 2'
18
+ gem.add_development_dependency 'rake', '>= 10', '< 20'
19
+ gem.add_development_dependency 'bundler', '>= 2', '< 3'
20
+
21
+ if RUBY_ENGINE == 'rbx'
22
+ gem.add_dependency 'rubysl', '~> 2.0'
23
+ end
24
+
25
+ # common
26
+
27
+ gem.authors = ['Kenichi Kamiya']
28
+ gem.email = ['kachick1+ruby@gmail.com']
29
+ gem.files = `git ls-files`.split($\)
30
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
31
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
32
+ gem.require_paths = ['lib']
33
+ end
34
+
@@ -0,0 +1,60 @@
1
+ # coding: us-ascii
2
+
3
+ $VERBOSE = true
4
+
5
+ require 'test/declare'
6
+ require_relative '../lib/struct/alias_member'
7
+
8
+ The Struct.new(:a1, :b2){alias_member :c3, :b2} do |klass|
9
+ The klass.members do
10
+ is [:a1, :b2]
11
+ end
12
+
13
+ The klass.aliases do
14
+ is({:c3 => :b2})
15
+ end
16
+
17
+ The klass.new do |instance|
18
+ ok {instance.member? :c3}
19
+ ng {instance.member? :d4}
20
+
21
+ CATCH KeyError do
22
+ instance[:e5]
23
+ end
24
+
25
+ The instance.values do
26
+ is [nil, nil]
27
+ end
28
+
29
+ The(instance[:c3] = 'OBJ') do
30
+ same instance[:b2]
31
+ same instance.b2
32
+ same instance[:c3]
33
+ same instance.c3
34
+ end
35
+
36
+ The instance.values do
37
+ is [nil, 'OBJ']
38
+ end
39
+
40
+ The(instance[:a1] = '123') do
41
+ same instance.a1
42
+ end
43
+
44
+ The instance[0] do
45
+ same instance.a1
46
+ end
47
+
48
+ The instance[1] do
49
+ same instance.b2
50
+ end
51
+
52
+ CATCH IndexError do
53
+ instance[2]
54
+ end
55
+
56
+ The instance.values do
57
+ is ['123', 'OBJ']
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: struct-alias_member
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenichi Kamiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-declare
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.20
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.20
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '10'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '20'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '10'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '20'
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '2'
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '3'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '2'
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: '3'
87
+ description: Struct will be able to alias the members name.
88
+ email:
89
+ - kachick1+ruby@gmail.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - ".travis.yml"
96
+ - ".yardopts"
97
+ - Gemfile
98
+ - MIT-LICENSE
99
+ - README.md
100
+ - Rakefile
101
+ - example/README.rb
102
+ - lib/struct/alias_member.rb
103
+ - lib/struct/alias_member/classmethods.rb
104
+ - lib/struct/alias_member/core_ext.rb
105
+ - lib/struct/alias_member/subclassclassmethods.rb
106
+ - lib/struct/alias_member/subclassinstancemethods.rb
107
+ - lib/struct/alias_member/version.rb
108
+ - struct-alias_member.gemspec
109
+ - test/test_basic.rb
110
+ homepage: http://kachick.github.com/struct-alias_member
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Struct will be able to alias the members name.
134
+ test_files:
135
+ - test/test_basic.rb