enel 0.0.1
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +165 -0
- data/Rakefile +8 -0
- data/enel.gemspec +26 -0
- data/lib/enel/version.rb +3 -0
- data/lib/enel.rb +23 -0
- data/spec/lib/enel_spec.rb +62 -0
- data/spec/spec_helper.rb +10 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ba58bcf88d57908c9ab72fed930fc527107b9d2
|
4
|
+
data.tar.gz: 2f5957ea7fa593fa21d37fdbc63be409734b5112
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 358e342b0dd96cf3015d568b34cadb13c1a38bc117e27fd5b6933baff30344ba5918a8806d026d2055b543ab19d095d7926dfd8eb10b4b48d3695fd87358749e
|
7
|
+
data.tar.gz: f26774e87f5df759b2f062e397269a0ec1093167cc8ca7583408ab3af6957b1648d7fe0413be46d18ce91ee6394d848e07d15ef76626cc8aa2b9c5c5fe69e4ce
|
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 tbpgr
|
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,165 @@
|
|
1
|
+
# :zap::angel: Enel
|
2
|
+
|
3
|
+
Remove duplicate logic that use thor.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/tbpgr/enel)
|
6
|
+
|
7
|
+
## :notes: Images
|
8
|
+
### :baby_chick: Before
|
9
|
+
|
10
|
+
:zap:
|
11
|
+
1 :turtle::rabbit::dragon:(1)
|
12
|
+
2 :turtle::rabbit::dragon:(2)
|
13
|
+
3 :turtle::rabbit::dragon:(3)
|
14
|
+
4 :turtle::rabbit::dragon:(4)
|
15
|
+
|
16
|
+
### :chicken: After
|
17
|
+
|
18
|
+
:zap::angel:
|
19
|
+
1
|
20
|
+
2
|
21
|
+
3
|
22
|
+
4
|
23
|
+
:sparkles::sparkles:
|
24
|
+
|
25
|
+
## :cloud::arrow_down: Installation
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'enel'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install enel
|
40
|
+
|
41
|
+
## :scroll: Usage
|
42
|
+
### :mouse: Sample Case
|
43
|
+
#### :baby_chick: Before use
|
44
|
+
|
45
|
+
* hoge.rb
|
46
|
+
|
47
|
+
~~~ruby
|
48
|
+
require 'thor'
|
49
|
+
require_relative './commands/hoges'
|
50
|
+
|
51
|
+
class Hoge < Thor
|
52
|
+
desc 'hoge1', 'hoge1'
|
53
|
+
def hoge1
|
54
|
+
puts Commands::Hoge1.run
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'hoge2', 'hoge2'
|
58
|
+
def hoge2(args1)
|
59
|
+
puts Commands::Hoge2.run(args1)
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'hoge3', 'hoge3'
|
63
|
+
def hoge3(args1, *options)
|
64
|
+
puts Commands::Hoge2.run(args1, *options)
|
65
|
+
end
|
66
|
+
|
67
|
+
# hoge4, hoge5... more!
|
68
|
+
end
|
69
|
+
|
70
|
+
Hoge.start(ARGV)
|
71
|
+
~~~
|
72
|
+
|
73
|
+
* ./commands/hoges.rb
|
74
|
+
|
75
|
+
~~~ruby
|
76
|
+
module Commands
|
77
|
+
class Hoge1
|
78
|
+
def run
|
79
|
+
"hoge1"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Hoge2
|
84
|
+
def run(args1)
|
85
|
+
args1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class Hoge3
|
90
|
+
def run(args1, *options)
|
91
|
+
[args1, *options]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# hoge4, hoge5... more!
|
96
|
+
end
|
97
|
+
~~~
|
98
|
+
|
99
|
+
* result
|
100
|
+
|
101
|
+
~~~
|
102
|
+
$ ruby hoge.rb hoge1
|
103
|
+
hoge1
|
104
|
+
$ ruby hoge.rb hoge2 a
|
105
|
+
a
|
106
|
+
$ ruby hoge.rb hoge3 a b c
|
107
|
+
a
|
108
|
+
b
|
109
|
+
c
|
110
|
+
~~~
|
111
|
+
|
112
|
+
#### :chicken: After use
|
113
|
+
~~~ruby
|
114
|
+
require 'thor'
|
115
|
+
require 'active_support/inflector'
|
116
|
+
require 'enel'
|
117
|
+
require_relative 'commands/hoges'
|
118
|
+
|
119
|
+
class Hoge < ::Thor
|
120
|
+
extend Enel
|
121
|
+
|
122
|
+
desc 'hoge1', 'hoge1'
|
123
|
+
def hoge1
|
124
|
+
end
|
125
|
+
|
126
|
+
desc 'hoge2', 'hoge2'
|
127
|
+
def hoge2(args1)
|
128
|
+
end
|
129
|
+
|
130
|
+
desc 'hoge3', 'hoge3'
|
131
|
+
def hoge3(args1, *options)
|
132
|
+
end
|
133
|
+
|
134
|
+
# hoge4, hoge5... more!
|
135
|
+
|
136
|
+
define_call_command(proc { |*args|
|
137
|
+
command = args.first.to_s.camelize
|
138
|
+
params = args[1..-1]
|
139
|
+
puts Object.const_get("Commands::#{command}").new.run(*params)
|
140
|
+
})
|
141
|
+
end
|
142
|
+
|
143
|
+
Hoge.start(ARGV)
|
144
|
+
~~~
|
145
|
+
|
146
|
+
* result
|
147
|
+
|
148
|
+
~~~
|
149
|
+
$ ruby hoge.rb hoge1
|
150
|
+
hoge1
|
151
|
+
$ ruby hoge.rb hoge2 a
|
152
|
+
a
|
153
|
+
$ ruby hoge.rb hoge3 a b c
|
154
|
+
a
|
155
|
+
b
|
156
|
+
c
|
157
|
+
~~~
|
158
|
+
|
159
|
+
## :two_men_holding_hands: Contributing :two_women_holding_hands:
|
160
|
+
|
161
|
+
1. Fork it ( https://github.com/tbpgr/enel/fork )
|
162
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
163
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
164
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
165
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/enel.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 'enel/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'enel'
|
8
|
+
spec.version = Enel::VERSION
|
9
|
+
spec.authors = ['tbpgr']
|
10
|
+
spec.email = ['tbpgr@tbpgr.jp']
|
11
|
+
spec.summary = 'Remove duplicate logic in thor commad.'
|
12
|
+
spec.description = 'Remove duplicate logic in thor commad.'
|
13
|
+
spec.homepage = 'https://github.com/tbpgr/enel'
|
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_development_dependency 'thor', '~> 0.19'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
end
|
data/lib/enel/version.rb
ADDED
data/lib/enel.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'enel/version'
|
2
|
+
|
3
|
+
module Enel
|
4
|
+
def define_call_command(proc)
|
5
|
+
no_commands do
|
6
|
+
define_method(:call_command) { |*args|proc.call(*args) }
|
7
|
+
end
|
8
|
+
private :call_command
|
9
|
+
define_each_commands
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def define_each_commands
|
15
|
+
instance_methods(false).each { |command|define_each_command(command) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def define_each_command(command)
|
19
|
+
no_commands do
|
20
|
+
define_method(command) { |*args|call_command(command, *args) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'enel'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
describe Enel do
|
7
|
+
context :define_call_command do
|
8
|
+
let(:hoge) do
|
9
|
+
class Hoge < ::Thor
|
10
|
+
extend Enel
|
11
|
+
|
12
|
+
desc 'all', 'show all boards [id,name]'
|
13
|
+
def all
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'find [board_id]', 'show board'
|
17
|
+
def find(_board_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
define_call_command(proc do |*args|
|
21
|
+
args
|
22
|
+
end)
|
23
|
+
end
|
24
|
+
Hoge.new
|
25
|
+
end
|
26
|
+
|
27
|
+
cases = [
|
28
|
+
{
|
29
|
+
case_no: 1,
|
30
|
+
case_title: 'case_title',
|
31
|
+
expected: [:all, 'args1', 'args2']
|
32
|
+
}
|
33
|
+
]
|
34
|
+
|
35
|
+
cases.each do |c|
|
36
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
37
|
+
begin
|
38
|
+
case_before c
|
39
|
+
|
40
|
+
# -- given --
|
41
|
+
# nothing
|
42
|
+
|
43
|
+
# -- when --
|
44
|
+
actual = hoge.all('args1', 'args2')
|
45
|
+
|
46
|
+
# -- then --
|
47
|
+
expect(actual).to eq(c[:expected])
|
48
|
+
ensure
|
49
|
+
case_after c
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def case_before(_c)
|
54
|
+
# implement each case before
|
55
|
+
end
|
56
|
+
|
57
|
+
def case_after(_c)
|
58
|
+
# implement each case after
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter '/spec/'
|
5
|
+
end
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tbpgr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.19'
|
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.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Remove duplicate logic in thor commad.
|
84
|
+
email:
|
85
|
+
- tbpgr@tbpgr.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- enel.gemspec
|
98
|
+
- lib/enel.rb
|
99
|
+
- lib/enel/version.rb
|
100
|
+
- spec/lib/enel_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/tbpgr/enel
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.3.0
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Remove duplicate logic in thor commad.
|
126
|
+
test_files:
|
127
|
+
- spec/lib/enel_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
has_rdoc:
|