kumadori 0.8.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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +108 -0
- data/Rakefile +7 -0
- data/kumadori.gemspec +26 -0
- data/lib/kumadori.rb +25 -0
- data/lib/kumadori/base_decorator.rb +13 -0
- data/lib/kumadori/version.rb +3 -0
- data/spec/kumadori_spec.rb +78 -0
- data/spec/spec_helper.rb +33 -0
- metadata +117 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: b0421db41b20a8dcb1720e0e7eb491a9739abead
|
|
4
|
+
data.tar.gz: 0a9b7faf7b051523905f712ac3c437c619d652b7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a52b67a33af92a001a62dcccdb5f58e06e637038559f318cfad4ebc050aa84f8aeb21f9776bba1b5fe53dccb101344bf473f24ac6d27efc7d0d9fc349aa798ed
|
|
7
|
+
data.tar.gz: 2f3771531fc5998db281d4caf028948596dae5b6b76755195f80c072fa8bfb7d1808977b0b469af11096acf7cd20f2c5acc95f584d56dafe0fd1cdeabd35f22f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Arakaki-Yuji
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
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
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Kumadori
|
|
2
|
+
|
|
3
|
+
This is simple decorator for Ruby.
|
|
4
|
+
|
|
5
|
+
Kumadori mean make-up for Japanese Kabuki.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'kumadori'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install kumadori
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Kumadori decorate your instance by #{instance.class}Decorator class.
|
|
26
|
+
|
|
27
|
+
````ruby
|
|
28
|
+
#
|
|
29
|
+
# Basic ruby class.
|
|
30
|
+
#
|
|
31
|
+
class User
|
|
32
|
+
attr_accesstor :first_name, :last_name
|
|
33
|
+
|
|
34
|
+
def initialize(first_name, last_name)
|
|
35
|
+
self.first_name = first_name
|
|
36
|
+
self.last_name = last_name
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
# Decorator class for User instance.
|
|
42
|
+
#
|
|
43
|
+
class UserDecorator < Kumadori::BaseDecorator
|
|
44
|
+
def full_name
|
|
45
|
+
"#{self.last_name} #{self.first_name}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
user = User.new('Yuji', 'Arakaki')
|
|
50
|
+
|
|
51
|
+
# user instance decorated by UserDecorator
|
|
52
|
+
decorated_user = Kumadori.decorate(user)
|
|
53
|
+
|
|
54
|
+
decorated_user.full_name # => "Arakaki Yuji"
|
|
55
|
+
|
|
56
|
+
````
|
|
57
|
+
|
|
58
|
+
if you not defined #{instance.class}Decorator class, it's instance decorated by Kumadori::BaseDecorator.
|
|
59
|
+
So, if you want defined method for every instance,
|
|
60
|
+
you just override Kumadori::BaseDecorator, and defined method.
|
|
61
|
+
|
|
62
|
+
````ruby
|
|
63
|
+
|
|
64
|
+
class Animal
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module Kumadori
|
|
68
|
+
class BaseDecorator < ::SimpleDelegator
|
|
69
|
+
def live?
|
|
70
|
+
true
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
animal = Animal.new
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# Because of AnimalDecorator class is not defiend,
|
|
79
|
+
# it is decorated by Kumadori::BaseDecorator
|
|
80
|
+
decorated_animal = Kumadori.decorate(animal)
|
|
81
|
+
|
|
82
|
+
decorated_animal.live? # => true
|
|
83
|
+
|
|
84
|
+
````
|
|
85
|
+
|
|
86
|
+
if you want to decorate all items in collection,
|
|
87
|
+
use Kumadori.collection_decorate method.
|
|
88
|
+
|
|
89
|
+
````ruby
|
|
90
|
+
|
|
91
|
+
members = []
|
|
92
|
+
members << User.new('Kanoko', 'Higa')
|
|
93
|
+
members << User.new('Ai', 'Kawasaki')
|
|
94
|
+
members << User.new('Takeo', 'Kikuchi')
|
|
95
|
+
|
|
96
|
+
decorated_members = Kumadori.collection_decorate(members)
|
|
97
|
+
|
|
98
|
+
decorated_members.map{ |user| user.full_name} # => ["Higa Kanoko", "Kawasaki Ai", "Kikuchi Takeo"]
|
|
99
|
+
|
|
100
|
+
````
|
|
101
|
+
|
|
102
|
+
## Contributing
|
|
103
|
+
|
|
104
|
+
1. Fork it ( https://github.com/[my-github-username]/kumadori/fork )
|
|
105
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
106
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
107
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
108
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/kumadori.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'kumadori/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "kumadori"
|
|
8
|
+
spec.version = Kumadori::VERSION
|
|
9
|
+
spec.authors = ["Arakaki-Yuji"]
|
|
10
|
+
spec.email = ["arakaki@ryukyu-i.co.jp"]
|
|
11
|
+
spec.summary = %q{This is simple decorator for ruby}
|
|
12
|
+
spec.description = %q{This is simple decorator for ruby. Kumadori mean makeup for Japanese Kabuki }
|
|
13
|
+
spec.homepage = "https://github.com/Arakaki-Yuji/kumadori"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
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_runtime_dependency 'activesupport', "~> 4.1"
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
|
26
|
+
end
|
data/lib/kumadori.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "kumadori/version"
|
|
2
|
+
require "rubygems"
|
|
3
|
+
require "delegate"
|
|
4
|
+
require "active_support/core_ext/string/inflections"
|
|
5
|
+
require "kumadori/base_decorator"
|
|
6
|
+
|
|
7
|
+
module Kumadori
|
|
8
|
+
def self.decorate(arg)
|
|
9
|
+
decorator_class(arg).new(arg)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.collection_decorate(args)
|
|
13
|
+
args.map{ |e| self.decorate(e) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.decorator_class(args)
|
|
17
|
+
class_name = args.class.to_s
|
|
18
|
+
decorator_name = "#{class_name}Decorator"
|
|
19
|
+
begin
|
|
20
|
+
return decorator_name.constantize
|
|
21
|
+
rescue NameError
|
|
22
|
+
return BaseDecorator
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Kumadori
|
|
2
|
+
#
|
|
3
|
+
# This class is base class for decorator.
|
|
4
|
+
# If it is not defined decorator for target instance,
|
|
5
|
+
# the instance is decorated by BaseDecorator class.
|
|
6
|
+
#
|
|
7
|
+
# If you want to defined that all decorated instance use method,
|
|
8
|
+
# you should override BaseDecorator class and defined it.
|
|
9
|
+
#
|
|
10
|
+
#
|
|
11
|
+
class BaseDecorator < ::SimpleDelegator
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Kumadori do
|
|
4
|
+
let(:custom_instance){ Custom.new }
|
|
5
|
+
let(:not_defined){ NotDefined.new }
|
|
6
|
+
|
|
7
|
+
it 'has a version number' do
|
|
8
|
+
expect(Kumadori::VERSION).not_to be nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe 'Kumadori.decorate(obj) return obj' do
|
|
12
|
+
let(:decorated){ Kumadori.decorate(custom_instance) }
|
|
13
|
+
|
|
14
|
+
context 'if #{obj.class}Decorator class was defined' do
|
|
15
|
+
it 'class name is #{obj.class}Decorator' do
|
|
16
|
+
expect(decorated.class).to eq(CustomDecorator)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'respond to method that defined in #{obj.class}Decorator class' do
|
|
20
|
+
expect(decorated.respond_to?(:custom_decorator_method)).to be true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'if #{obj.class}Decorator class was not defined' do
|
|
25
|
+
let(:not_defined_decorated) { Kumadori.decorate(not_defined) }
|
|
26
|
+
|
|
27
|
+
it "class name is Kumadori::BaseDecorator" do
|
|
28
|
+
expect(not_defined_decorated.class).to eq(Kumadori::BaseDecorator)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'not respond to method that defined in #{obj.class}Decorator class' do
|
|
32
|
+
expect(not_defined_decorated.respond_to?(:custom_decorator_method)).to be false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'respond to method that defined in BaseDecorator class' do
|
|
36
|
+
expect(not_defined_decorated.respond_to?(:base_decorator_method)).to be true
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
it 'respond to method that defined in BaseDecorator class' do
|
|
42
|
+
expect(decorated.respond_to?(:base_decorator_method)).to be true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'respond to method that defined in obj class' do
|
|
46
|
+
expect(decorated.respond_to?(:custom_method)).to be true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe 'if #{obj.class}Decorator defined same name method with obj.class' do
|
|
50
|
+
it 'respond to method that defined in #{obj.class}Decorator class' do
|
|
51
|
+
expect(decorated.same_name_method).to eq('Call from CustomDecorator class')
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
describe "Kumador.collection_decorate(objs) return objs" do
|
|
59
|
+
|
|
60
|
+
let(:collection) do
|
|
61
|
+
collection = []
|
|
62
|
+
5.times do
|
|
63
|
+
collection << Custom.new
|
|
64
|
+
end
|
|
65
|
+
5.times do
|
|
66
|
+
collection << NotDefined.new
|
|
67
|
+
end
|
|
68
|
+
collection
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "all objs is BaseDecorator or Kumadori::BaseDecorator's child class" do
|
|
72
|
+
decorated_collection = Kumadori.collection_decorate(collection)
|
|
73
|
+
decorated_collection.each do |obj|
|
|
74
|
+
expect(obj.is_a?(Kumadori::BaseDecorator)).to be true
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require 'kumadori'
|
|
3
|
+
|
|
4
|
+
module Kumadori
|
|
5
|
+
class BaseDecorator < ::SimpleDelegator
|
|
6
|
+
def base_decorator_method(name)
|
|
7
|
+
"goodbye, #{name}"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class CustomDecorator < Kumadori::BaseDecorator
|
|
13
|
+
def custom_decorator_method(name)
|
|
14
|
+
"hello #{name}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def same_name_method
|
|
18
|
+
"Call from CustomDecorator class"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Custom
|
|
23
|
+
def custom_method(name)
|
|
24
|
+
"good job, #{name}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def same_name_method
|
|
28
|
+
"Call from Custom class"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class NotDefined
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kumadori
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.8.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Arakaki-Yuji
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.7'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.7'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.2'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.2'
|
|
69
|
+
description: 'This is simple decorator for ruby. Kumadori mean makeup for Japanese
|
|
70
|
+
Kabuki '
|
|
71
|
+
email:
|
|
72
|
+
- arakaki@ryukyu-i.co.jp
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".gitignore"
|
|
78
|
+
- ".rspec"
|
|
79
|
+
- ".travis.yml"
|
|
80
|
+
- Gemfile
|
|
81
|
+
- LICENSE.txt
|
|
82
|
+
- README.md
|
|
83
|
+
- Rakefile
|
|
84
|
+
- kumadori.gemspec
|
|
85
|
+
- lib/kumadori.rb
|
|
86
|
+
- lib/kumadori/base_decorator.rb
|
|
87
|
+
- lib/kumadori/version.rb
|
|
88
|
+
- spec/kumadori_spec.rb
|
|
89
|
+
- spec/spec_helper.rb
|
|
90
|
+
homepage: https://github.com/Arakaki-Yuji/kumadori
|
|
91
|
+
licenses:
|
|
92
|
+
- MIT
|
|
93
|
+
metadata: {}
|
|
94
|
+
post_install_message:
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubyforge_project:
|
|
110
|
+
rubygems_version: 2.2.0
|
|
111
|
+
signing_key:
|
|
112
|
+
specification_version: 4
|
|
113
|
+
summary: This is simple decorator for ruby
|
|
114
|
+
test_files:
|
|
115
|
+
- spec/kumadori_spec.rb
|
|
116
|
+
- spec/spec_helper.rb
|
|
117
|
+
has_rdoc:
|