dekoden 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 201397aab0aa5ea9dcaaffade6e18949ee17c442
4
+ data.tar.gz: a5cbd585ccfc7f92fe8b534bcb03f291313e3948
5
+ SHA512:
6
+ metadata.gz: 5f2bbdb4749b00dc6832b9b5a628017becb8edc3da0d37eda3fa3af0d505919f0434e81a8a30fbbd2022e3d6799c11af3d3154ccf040b6dad764d3f8d473bb8c
7
+ data.tar.gz: 8499be205382ec46564a086b1c53af0f5fd20515bb180d0449ffb469093b28c05c00ed51718dcbf87b775498c30f5f326430e8afbae1b6c6a93b9a3d4639b510
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dekoden.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Adrien Katsuya Tateno
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,112 @@
1
+ # dekoden
2
+ dekoden decorates methods.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem "dekoden"
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install dekoden
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require "dekoden"
24
+
25
+ module MyCollection
26
+ class MyDecorator
27
+ def initialize(suffix)
28
+ @suffix = suffix
29
+ end
30
+
31
+ def call(*args, blk)
32
+ yield(*args, blk) + @suffix
33
+ end
34
+ end
35
+ end
36
+
37
+ class MyClass
38
+ extend Dekoden::Decoratable
39
+ decorators MyCollection
40
+
41
+ MyDecorator " World"
42
+ def my_method(message)
43
+ message
44
+ end
45
+ end
46
+
47
+ MyClass.new.my_method("Hello")
48
+ # => "Hello World"
49
+
50
+ # Make all classes and modules decoratable
51
+ class Module
52
+ include Dekoden::Decoratable
53
+ end
54
+
55
+ # Make decorators available to all classes and modules
56
+ class Module
57
+ include Dekoden::Decoratable
58
+ singleton_decorators MyCollection
59
+ end
60
+
61
+ # Instance methods (inherited)
62
+
63
+ class MyClass
64
+ MyDecorator " World"
65
+ def my_method(message)
66
+ message
67
+ end
68
+ end
69
+
70
+ # Class methods (inherited)
71
+
72
+ class MyClass
73
+ MyDecorator " World"
74
+ def self.my_method(message)
75
+ message
76
+ end
77
+ end
78
+
79
+ # Module methods (to be included)
80
+
81
+ module MyModule
82
+ MyDecorator " World"
83
+ def my_method(message)
84
+ message
85
+ end
86
+ end
87
+
88
+ # Module methods (to be called directly or extended)
89
+
90
+ class MyModule
91
+ MyDecorator " World"
92
+ def self.my_method(message)
93
+ message
94
+ end
95
+ end
96
+ ```
97
+
98
+ ## Development
99
+
100
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests.
101
+
102
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/katsuya94/dekoden.
107
+
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
112
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dekoden/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dekoden"
8
+ spec.version = Dekoden::VERSION
9
+ spec.authors = ["Adrien Katsuya Tateno"]
10
+ spec.email = ["adrien.k.tateno@gmail.com"]
11
+
12
+ spec.summary = %q{dekoden decorates methods}
13
+ spec.homepage = "https://github.com/katsuya94/dekoden"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^spec/})
18
+ end
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.13"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
25
+ end
@@ -0,0 +1,101 @@
1
+ require "dekoden/version"
2
+
3
+ module Dekoden
4
+ module SingletonPrependMethods
5
+ def method_added(method_name)
6
+ unless unbound_decorators.empty?
7
+ decorators_for_method = unbound_decorators.dup
8
+ unbound_decorators.clear
9
+ decorated_methods.module_eval do
10
+ define_method(method_name) do |*args, &blk|
11
+ Helpers.wrap(decorators_for_method, *args, blk) do |*args, blk|
12
+ super(*args, &blk)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ super
18
+ end
19
+
20
+ def singleton_method_added(method_name)
21
+ unless unbound_decorators.empty?
22
+ decorators_for_method = unbound_decorators.dup
23
+ unbound_decorators.clear
24
+ decorated_singleton_methods.module_eval do
25
+ define_method(method_name) do |*args, &blk|
26
+ Helpers.wrap(decorators_for_method, *args, blk) do |*args, blk|
27
+ super(*args, &blk)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ super
33
+ end
34
+ end
35
+
36
+ module Decoratable
37
+ def decorators(*mojules)
38
+ mojules.each do |mojule|
39
+ mojule.constants.each do |constant|
40
+ decorator_klass = mojule.const_get(constant)
41
+ define_singleton_method(constant) do |*args, &blk|
42
+ unbound_decorators << decorator_klass.new(*args, &blk)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def singleton_decorators(*mojules)
49
+ mojules.each do |mojule|
50
+ mojule.constants.each do |constant|
51
+ decorator_klass = mojule.const_get(constant)
52
+ define_method(constant) do |*args, &blk|
53
+ unbound_decorators << decorator_klass.new(*args, &blk)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def unbound_decorators
60
+ @unbound_decorators ||= []
61
+ end
62
+
63
+ def decorated_methods
64
+ unless const_defined?(:DecoratedMethods, false)
65
+ mojule = Module.new
66
+ self.prepend(mojule)
67
+ self.const_set(:DecoratedMethods, mojule)
68
+ end
69
+ self.const_get(:DecoratedMethods)
70
+ end
71
+
72
+ def decorated_singleton_methods
73
+ unless const_defined?(:DecoratedSingletonMethods, false)
74
+ mojule = Module.new
75
+ self.singleton_class.prepend(mojule)
76
+ self.const_set(:DecoratedSingletonMethods, mojule)
77
+ end
78
+ self.const_get(:DecoratedSingletonMethods)
79
+ end
80
+
81
+ def self.extended(mojule)
82
+ mojule.singleton_class.prepend(SingletonPrependMethods)
83
+ end
84
+
85
+ def self.included(mojule)
86
+ mojule.prepend(SingletonPrependMethods)
87
+ end
88
+ end
89
+
90
+ module Helpers
91
+ def self.wrap(decorators, *args, blk, &block)
92
+ if decorator = decorators.first
93
+ decorator.call(*args, blk) do |*args, blk|
94
+ wrap(decorators.drop(1), *args, blk, &block)
95
+ end
96
+ else
97
+ block.call(*args, blk)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module Dekoden
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dekoden
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Katsuya Tateno
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-20 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ description:
70
+ email:
71
+ - adrien.k.tateno@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - dekoden.gemspec
84
+ - lib/dekoden.rb
85
+ - lib/dekoden/version.rb
86
+ homepage: https://github.com/katsuya94/dekoden
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: dekoden decorates methods
110
+ test_files: []