hashize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f62f3e45db98aa8e6642436332a5f2f91b2046f1
4
+ data.tar.gz: 523ef22fd8da463eb3fb5c0dedabcd4a5afe64b6
5
+ SHA512:
6
+ metadata.gz: 0ed7b0e8fca5160bbe3cac028470e6322cd5177a14c21d40f958274b4148b08a2d46dae694697142006b2b4651efd2a720c5c30057ace414a753f0cac8583755
7
+ data.tar.gz: cedd00ba7d58e74d505b370dbf75c04f15af4152203332f639f70d416e1cb6d81ab1319655082a401e7be3781865c694ed79092e52010f19c5df8c2a66985445
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hashize.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,67 @@
1
+ Github_Markdown_API
2
+ ===================
3
+
4
+ Github Markdown API client and command-line tool.
5
+
6
+ You can redistribute it and/or modify it under either the terms of the GPL Version 3 or NYSL(0.9982).
7
+
8
+ NYSL(ja)
9
+ --------
10
+
11
+ > A. 本ソフトウェアは Everyone'sWare です。このソフトを手にした一人一人が、
12
+ > ご自分の作ったものを扱うのと同じように、自由に利用することが出来ます。
13
+ >
14
+ > A-1. フリーウェアです。作者からは使用料等を要求しません。
15
+ > A-2. 有料無料や媒体の如何を問わず、自由に転載・再配布できます。
16
+ > A-3. いかなる種類の 改変・他プログラムでの利用 を行っても構いません。
17
+ > A-4. 変更したものや部分的に使用したものは、あなたのものになります。
18
+ > 公開する場合は、あなたの名前の下で行って下さい。
19
+ >
20
+ > B. このソフトを利用することによって生じた損害等について、作者は
21
+ > 責任を負わないものとします。各自の責任においてご利用下さい。
22
+ >
23
+ > C. 著作者人格権は ZonuEXE(Kusami, tadsan@zonu.me) に帰属します。著作権は放棄します。
24
+
25
+ > D. 以上の3項は、ソース・実行バイナリの双方に適用されます。
26
+
27
+ NYSL(en, Unofficial)
28
+ --------------------
29
+
30
+ > A. This software is "Everyone'sWare". It means:
31
+ > Anybody who has this software can use it as if he/she is
32
+ > the author.
33
+ >
34
+ > A-1. Freeware. No fee is required.
35
+ > A-2. You can freely redistribute this software.
36
+ > A-3. You can freely modify this software. And the source
37
+ > may be used in any software with no limitation.
38
+ > A-4. When you release a modified version to public, you
39
+ > must publish it with your name.
40
+ >
41
+ > B. The author is not responsible for any kind of damages or loss
42
+ > while using or misusing this software, which is distributed
43
+ > "AS IS". No warranty of any kind is expressed or implied.
44
+ > You use AT YOUR OWN RISK.
45
+ >
46
+ > C. Copyrighted to USAMI Kenta <tadsan@zonu.me>
47
+ >
48
+ > D. Above three clauses are applied both to source and binary
49
+ > form of this software.
50
+
51
+ GPLv3
52
+ -----
53
+
54
+ > Copyright (C) 2012 Kusami, USAMI Kenta <<tadsan@zonu.me>>
55
+ >
56
+ > This program is free software: you can redistribute it and/or modify
57
+ > it under the terms of the GNU General Public License as published by
58
+ > the Free Software Foundation, either version 3 of the License, or
59
+ > (at your option) any later version.
60
+ >
61
+ > This program is distributed in the hope that it will be useful,
62
+ > but WITHOUT ANY WARRANTY; without even the implied warranty of
63
+ > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64
+ > GNU General Public License for more details.
65
+ >
66
+ > You should have received a copy of the GNU General Public License
67
+ > along with this program. If not, see <http://www.gnu.org/licenses/>.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ Hashize
2
+ =======
3
+
4
+ Refinements classes of ruby's standard library as Hash
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'hashize'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hashize
20
+
21
+ Supports Classes
22
+ ----------------
23
+
24
+ ### Standard Class
25
+
26
+ * `Struct`
27
+
28
+ ### Standard Library
29
+
30
+ * `URI::Generic` (`uri`)
31
+
32
+ Usage
33
+ -----
34
+
35
+ In your code:
36
+
37
+ ```ruby
38
+ require 'hashize'
39
+ using Hashize::URI::Generic
40
+ using Hashize::Struct
41
+
42
+ uri = URI::parse('http://dt.zonu.me/').to_hash
43
+ #=> {:scheme => "http",
44
+ # :userinfo => nil,
45
+ # :host => "dt.zonu.me",
46
+ # :port => 80,
47
+ # :path => "/",
48
+ # :query => nil,
49
+ # :fragment => nil}
50
+
51
+ MyStruct = Struct.new(:foo, :bar, :buz)
52
+ my = MyStruct.new('FOO', 'BAR', 'BUZ')
53
+ my.to_Hash
54
+ #=> {:foo => "FOO",
55
+ # :bar => "BAR",
56
+ # :buz => "BUZ"}
57
+ ```
58
+
59
+ Contributing
60
+ ------------
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/hashize.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hashize/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hashize"
8
+ spec.version = Hashize::VERSION
9
+ spec.authors = ["USAMI Kenta"]
10
+ spec.email = ["tadsan@zonu.me"]
11
+ spec.description = %q{Refinements classes of ruby's standard library as Hash}
12
+ spec.summary = %q{Ruby has strict policy, and there are many class which do not have to_hash in Standard Library. Hashize provides Hash-like methods for some class in small scope by refinements.}
13
+ spec.homepage = 'http://dt.zonu.me/'
14
+ spec.licenses = %w(LGPLv3 NYSL)
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/hashize.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'hashize/version'
2
+ require 'hashize/uri-generic'
3
+ require 'hashize/struct'
@@ -0,0 +1,16 @@
1
+ require 'hashize/version'
2
+
3
+ # Refinements method of Struct
4
+ module Hashize::Struct
5
+ refine Struct do
6
+ def keys
7
+ self.members
8
+ end
9
+
10
+ def to_hash
11
+ Hash[self.class.members.zip(self.to_a)]
12
+ end
13
+
14
+ def to_h; to_hash; end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'uri'
2
+ require 'hashize/version'
3
+
4
+ # Dummy namespace
5
+ module Hashize::URI; end
6
+
7
+ # Refinements method of URI::Generic
8
+ # @see URI::Generic
9
+ module Hashize::URI::Generic
10
+ refine URI::Generic do
11
+ def keys
12
+ self.component
13
+ end
14
+
15
+ def values
16
+ self.component_ary
17
+ end
18
+
19
+ def to_hash
20
+ Hash[self.component.zip(self.component_ary)]
21
+ end
22
+
23
+ def to_h; to_hash; end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'uri'
2
+ require 'hashize/uri-generic'
@@ -0,0 +1,5 @@
1
+ # Namespace of Hashize
2
+ module Hashize
3
+ # Version number of Hashize
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..','spec_helper'))
2
+ require 'hashize/struct'
3
+
4
+ using Hashize::Struct
5
+
6
+ describe Hashize::Struct do
7
+ describe "" do
8
+ before(:all){ Hoge = Struct.new(:fizz, :buzz) }
9
+ subject{ Hoge.new('FIZZ', 'BUZZ') }
10
+ it{ expect(subject.to_hash).to eq({
11
+ fizz: 'FIZZ',
12
+ buzz: 'BUZZ'
13
+ })
14
+ }
15
+ context "in Ruby 2.0.0" do
16
+ it{ expect(subject.respond_to? :to_hash).to be_false }
17
+ it{ expect{subject.send(:to_hash)}.to raise_error NoMethodError }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..','spec_helper'))
2
+ require 'hashize/uri-generic'
3
+
4
+ using Hashize::URI::Generic
5
+
6
+ describe Hashize::URI::Generic do
7
+ describe "URI::HTTP instance object" do
8
+ subject{ ::URI::parse('http://example.com/path/to/examples?foo=bar&fizz=buzz#A_HOGE') }
9
+ it{ expect(subject.to_hash).to eq({
10
+ fragment: 'A_HOGE',
11
+ host: 'example.com',
12
+ path: '/path/to/examples',
13
+ port: 80,
14
+ query: 'foo=bar&fizz=buzz',
15
+ scheme: 'http',
16
+ userinfo: nil
17
+ })
18
+ }
19
+ context "in Ruby 2.0.0" do
20
+ it{ expect(subject.respond_to? :to_hash).to be_false }
21
+ it{ expect{subject.send(:to_hash)}.to raise_error NoMethodError }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..','lib'))
2
+
3
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hashize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - USAMI Kenta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Refinements classes of ruby's standard library as Hash
42
+ email:
43
+ - tadsan@zonu.me
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .yardopts
50
+ - Gemfile
51
+ - LICENSE.md
52
+ - README.md
53
+ - Rakefile
54
+ - hashize.gemspec
55
+ - lib/hashize.rb
56
+ - lib/hashize/struct.rb
57
+ - lib/hashize/uri-generic.rb
58
+ - lib/hashize/uri.rb
59
+ - lib/hashize/version.rb
60
+ - spec/hashize/struct_spec.rb
61
+ - spec/hashize/uri-generic_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: http://dt.zonu.me/
64
+ licenses:
65
+ - LGPLv3
66
+ - NYSL
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.0.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Ruby has strict policy, and there are many class which do not have to_hash
88
+ in Standard Library. Hashize provides Hash-like methods for some class in small
89
+ scope by refinements.
90
+ test_files:
91
+ - spec/hashize/struct_spec.rb
92
+ - spec/hashize/uri-generic_spec.rb
93
+ - spec/spec_helper.rb
94
+ has_rdoc: