Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Sep 16, 2012
1 parent 1fa9fd8 commit eaafcca
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 50 deletions.
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ rvm:
- ruby-head
- 1.9.3
- 1.9.2
- rbx-19mode # Rubinius in 1.9 mode
- rbx-19mode
- jruby-head
- jruby-19mode # JRuby in 1.9 mode

- jruby-19mode

matrix:
allow_failures:
- rvm: rbx-19mode
- rvm: jruby-head
- rvm: jruby-19mode
1 change: 1 addition & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--readme README.md --private lib/**/*.rb - LICENSE
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ gemspec

group :development do
gem 'rake'
gem 'yard', '>=0.8.2.1'
gem 'yard', '~> 0.8'
end

group :test do
gem 'rake'
gem 'test-declare', '~>0.0.2.1'
gem 'test-declare', '~> 0.0.2'
end
13 changes: 9 additions & 4 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
README.rdoc
README.md
LICENSE
History.rdoc
History.md
Manifest.txt
Rakefile
Gemfile
struct-alias_member.gemspec

lib/struct/alias_member.rb
lib/struct/alias_member/version.rb
lib/struct/alias_member/classmethods.rb
lib/struct/alias_member/instancemethods.rb
lib/struct/alias_member/core_ext.rb
dspec/basic.rb
example/basic.rb

test/test_basic.rb

example/README.rb
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Struct.#alias_member
===================
struct-alias_member
====================

Standard Struct will be able to member aliasing.

Expand Down Expand Up @@ -27,31 +27,27 @@ ac.aliases #=> {:money=>:balance}
Requirements
------------

* Ruby 1.9.2 or later

[MRI/YARV, Rubinius, JRuby](http://travis-ci.org/#!/kachick/struct-alias_member)
* Ruby - [1.9.2 or later](http://travis-ci.org/#!/kachick/struct-alias_member)

Install
-------

```shell
```bash
$ gem install struct-alias_member
```

Link
----

* code: https://github.com/kachick/struct-alias_member
* issues: https://github.com/kachick/struct-alias_member/issues
* CI: http://travis-ci.org/#!/kachick/struct-alias_member
* gem: https://rubygems.org/gems/struct-alias_member
* gem+: http://metagem.info/gems/struct-alias_member
* [code](https://github.com/kachick/struct-alias_member)
* [API](http://kachick.github.com/struct-alias_member/yard/frames.html)
* [issues](https://github.com/kachick/struct-alias_member/issues)
* [CI](http://travis-ci.org/#!/kachick/struct-alias_member)
* [gem](https://rubygems.org/gems/struct-alias_member)

License
-------

The MIT X License

Copyright (c) 2012 Kenichi Kamiya

The MIT X11 License
Copyright (c) 2012 Kenichi Kamiya
See the file LICENSE for further details.
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ task default: [:test]
Rake::TestTask.new do |tt|
tt.verbose = true
end

File renamed without changes.
2 changes: 1 addition & 1 deletion lib/struct/alias_member.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012 Kenichi Kamiya
# Copyright (c) 2012 Kenichi Kamiya

require_relative 'alias_member/version'
require_relative 'alias_member/classmethods'
Expand Down
23 changes: 11 additions & 12 deletions lib/struct/alias_member/classmethods.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
# Copyright (C) 2012 Kenichi Kamiya

class Struct; module Alias_Member

module ClassMethods

# @return [Array<Symbol>]
# @return [Hash] aliasA => autonymX, aliasB => autonymY
def aliases
@aliases.dup
end

# @param [Symbol, String] name
# @param [Symbol, String, #to_sym] name
# @return [Symbol]
def autonym(name)
name = name.to_sym

members.include?(name) ? name : @aliases.fetch(name)
end

# @param [Symbol, String] aliased
# @param [Symbol, String] source
# @param [Symbol, String, #to_sym] aliased
# @param [Symbol, String, #to_sym] autonym
# @return [Module]
def alias_member(aliased, source)
def alias_member(aliased, autonym)
class_eval do
aliased, source = aliased.to_sym, source.to_sym
aliased, autonym = aliased.to_sym, autonym.to_sym
if @aliases.has_key?(aliased) or members.include?(aliased)
raise Alias_Member::ArleadyDefinedError
end

@aliases[aliased] = source
@aliases[aliased] = autonym

alias_method aliased, source
alias_method :"#{aliased}=", :"#{source}="
alias_method aliased, autonym
alias_method :"#{aliased}=", :"#{autonym}="
end
end

end

end; end
end; end
15 changes: 9 additions & 6 deletions lib/struct/alias_member/instancemethods.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
# Copyright (C) 2012 Kenichi Kamiya

class Struct; module Alias_Member

module InstanceMethods

# @param [Symbol, String, #to_sym, Fixnum] key
def [](key)
case key
when Symbol, String
super self.class.autonym(key)
else
super
super key, value
end
end

# @return [value]
# @param [Symbol, String, #to_sym, Fixnum] key
# @return value
def []=(key, value)
case key
when Symbol, String
super self.class.autonym(key), value
else
super
super key, value
end
end

# @return [Array<Symbol>]
# @see [ClassMethods#aliases]
# @return [Hash]
def aliases
self.class.aliases
end

# @param [Symbol, String, #to_sym] name
def member?(name)
name = name.to_sym

members.include?(name) || aliases.has_key?(name)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/struct/alias_member/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Struct

module Alias_Member

VERSION = '0.0.1.1'.freeze
VERSION = '0.0.2.a'.freeze

end

Expand Down
11 changes: 6 additions & 5 deletions struct-alias_member.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ require File.expand_path('../lib/struct/alias_member/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ['Kenichi Kamiya']
gem.email = ['kachick1+ruby@gmail.com']
gem.summary = %q{Validate pair-object's key.}
gem.description = %q{e.g. Check option parameters are valid for a method.}
gem.summary = %q{Validate key-value pair's keys.}
gem.description = %q{Validate key-value pair's keys.
e.g. Check option parameters are valid for a method.}
gem.homepage = 'https://github.com/kachick/struct-alias_member'

gem.files = `git ls-files`.split($\)
Expand All @@ -14,8 +15,8 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.version = Struct::Alias_Member::VERSION.dup # dup for https://github.com/rubygems/rubygems/commit/48f1d869510dcd325d6566df7d0147a086905380#-P0

gem.required_ruby_version = '>=1.9.2'
gem.add_development_dependency 'test-declare', '~>0.0.2.1'
gem.add_development_dependency 'yard', '>=0.8.2.1'
gem.required_ruby_version = '>= 1.9.2'
gem.add_development_dependency 'test-declare', '~> 0.0.2'
gem.add_development_dependency 'yard', '~> 0.8'
end

0 comments on commit eaafcca

Please sign in to comment.