cl 0.0.4 → 0.1.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 +5 -5
- data/CHANGELOG.md +47 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +22 -12
- data/NOTES.md +2 -24
- data/README.md +1 -1
- data/examples/args/cast +82 -0
- data/examples/args/opts +36 -0
- data/examples/args/required +46 -0
- data/examples/args/splat +61 -0
- data/examples/gem +104 -0
- data/examples/heroku +49 -0
- data/examples/{multi.rb → rakeish} +13 -11
- data/lib/cl/arg.rb +12 -30
- data/lib/cl/args.rb +8 -5
- data/lib/cl/cast.rb +29 -0
- data/lib/cl/cmd.rb +65 -17
- data/lib/cl/config/env.rb +52 -0
- data/lib/cl/config/files.rb +34 -0
- data/lib/cl/config.rb +30 -0
- data/lib/cl/ctx.rb +29 -0
- data/lib/cl/help/cmd.rb +142 -0
- data/lib/cl/help/cmds.rb +28 -0
- data/lib/cl/help/table.rb +45 -0
- data/lib/cl/{format → help}/usage.rb +10 -4
- data/lib/cl/help.rb +10 -12
- data/lib/cl/helper.rb +11 -0
- data/lib/cl/opt.rb +141 -0
- data/lib/cl/opts.rb +155 -0
- data/lib/cl/parser.rb +39 -0
- data/lib/cl/runner/default.rb +35 -19
- data/lib/cl/runner/multi.rb +6 -7
- data/lib/cl/ui.rb +137 -0
- data/lib/cl/version.rb +2 -2
- data/lib/cl.rb +64 -19
- metadata +40 -18
- data/examples/args/cast.rb +0 -63
- data/examples/args/opts.rb +0 -32
- data/examples/args/required.rb +0 -35
- data/examples/args/splat.rb +0 -52
- data/examples/gem.rb +0 -81
- data/examples/heroku.rb +0 -41
- data/lib/cl/format/cmd.rb +0 -31
- data/lib/cl/format/list.rb +0 -22
- data/lib/cl/format/table.rb +0 -19
- data/lib/cl/options.rb +0 -13
- data/lib/cl/registry.rb +0 -53
metadata
CHANGED
@@ -1,46 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: regstry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.3
|
13
27
|
description: OptionParser based CLI support.
|
14
28
|
email:
|
15
29
|
executables: []
|
16
30
|
extensions: []
|
17
31
|
extra_rdoc_files: []
|
18
32
|
files:
|
33
|
+
- CHANGELOG.md
|
19
34
|
- Gemfile
|
20
35
|
- Gemfile.lock
|
21
36
|
- MIT_LICENSE.md
|
22
37
|
- NOTES.md
|
23
38
|
- README.md
|
24
|
-
- examples/args/cast
|
25
|
-
- examples/args/opts
|
26
|
-
- examples/args/required
|
27
|
-
- examples/args/splat
|
28
|
-
- examples/gem
|
29
|
-
- examples/heroku
|
30
|
-
- examples/
|
39
|
+
- examples/args/cast
|
40
|
+
- examples/args/opts
|
41
|
+
- examples/args/required
|
42
|
+
- examples/args/splat
|
43
|
+
- examples/gem
|
44
|
+
- examples/heroku
|
45
|
+
- examples/rakeish
|
31
46
|
- lib/cl.rb
|
32
47
|
- lib/cl/arg.rb
|
33
48
|
- lib/cl/args.rb
|
49
|
+
- lib/cl/cast.rb
|
34
50
|
- lib/cl/cmd.rb
|
35
|
-
- lib/cl/
|
36
|
-
- lib/cl/
|
37
|
-
- lib/cl/
|
38
|
-
- lib/cl/
|
51
|
+
- lib/cl/config.rb
|
52
|
+
- lib/cl/config/env.rb
|
53
|
+
- lib/cl/config/files.rb
|
54
|
+
- lib/cl/ctx.rb
|
39
55
|
- lib/cl/help.rb
|
40
|
-
- lib/cl/
|
41
|
-
- lib/cl/
|
56
|
+
- lib/cl/help/cmd.rb
|
57
|
+
- lib/cl/help/cmds.rb
|
58
|
+
- lib/cl/help/table.rb
|
59
|
+
- lib/cl/help/usage.rb
|
60
|
+
- lib/cl/helper.rb
|
61
|
+
- lib/cl/opt.rb
|
62
|
+
- lib/cl/opts.rb
|
63
|
+
- lib/cl/parser.rb
|
42
64
|
- lib/cl/runner/default.rb
|
43
65
|
- lib/cl/runner/multi.rb
|
66
|
+
- lib/cl/ui.rb
|
44
67
|
- lib/cl/version.rb
|
45
68
|
homepage: https://github.com/svenfuchs/cl
|
46
69
|
licenses:
|
@@ -61,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
84
|
- !ruby/object:Gem::Version
|
62
85
|
version: '0'
|
63
86
|
requirements: []
|
64
|
-
|
65
|
-
rubygems_version: 2.6.11
|
87
|
+
rubygems_version: 3.0.3
|
66
88
|
signing_key:
|
67
89
|
specification_version: 4
|
68
90
|
summary: OptionParser based CLI support
|
data/examples/args/cast.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'cl'
|
2
|
-
|
3
|
-
class Bool < Cl::Cmd
|
4
|
-
arg :bool, type: :bool
|
5
|
-
|
6
|
-
def run
|
7
|
-
[self.registry_key, bool: bool]
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Types < Cl::Cmd
|
12
|
-
arg :a, type: :bool
|
13
|
-
arg :b, type: :int
|
14
|
-
arg :c, type: :float
|
15
|
-
arg :d
|
16
|
-
|
17
|
-
def run
|
18
|
-
[self.registry_key, a: a, b: b, c: c, d: d]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def output(cmd, args)
|
23
|
-
args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
|
24
|
-
puts "Called #{cmd} with #{args}"
|
25
|
-
end
|
26
|
-
|
27
|
-
output *Cl.run(*%w(bool on))
|
28
|
-
# Output:
|
29
|
-
# Called bool with bool=true
|
30
|
-
|
31
|
-
output *Cl.run(*%w(bool on))
|
32
|
-
# Output:
|
33
|
-
# Called bool with bool=true
|
34
|
-
|
35
|
-
output *Cl.run(*%w(bool on))
|
36
|
-
# Output:
|
37
|
-
# Called bool with bool=true
|
38
|
-
|
39
|
-
output *Cl.run(*%w(bool on))
|
40
|
-
# Output:
|
41
|
-
# Called bool with bool=true
|
42
|
-
|
43
|
-
output *Cl.run(*%w(types true 1 1.2 foo))
|
44
|
-
# Output:
|
45
|
-
# Called types with a=true b=1 c=1.2 d="foo"
|
46
|
-
|
47
|
-
output *Cl.run(*%w(types true 1 1.2))
|
48
|
-
# Output:
|
49
|
-
# Too many arguments (given: 5, allowed: 4)
|
50
|
-
#
|
51
|
-
# Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
|
52
|
-
|
53
|
-
output *Cl.run(*%w(types true one 1.2))
|
54
|
-
# Output:
|
55
|
-
# Wrong argument type (given: "one", expected: int)
|
56
|
-
#
|
57
|
-
# Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
|
58
|
-
|
59
|
-
output *Cl.run(*%w(types true 1 one))
|
60
|
-
# Output:
|
61
|
-
# Wrong argument type (given: "one", expected: float)
|
62
|
-
#
|
63
|
-
# Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
|
data/examples/args/opts.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'cl'
|
2
|
-
|
3
|
-
class Opts < Cl::Cmd
|
4
|
-
opt '-p', '--path PATH' do |value|
|
5
|
-
opts[:path] = value
|
6
|
-
end
|
7
|
-
|
8
|
-
opt '-v', '--verbose' do
|
9
|
-
opts[:verbose] = true
|
10
|
-
end
|
11
|
-
|
12
|
-
def run
|
13
|
-
[self.registry_key, args, opts]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def output(cmd, args, opts)
|
18
|
-
puts "Called #{cmd} with args=#{args} opts=#{opts}"
|
19
|
-
end
|
20
|
-
|
21
|
-
output *Cl.run(*%w(opts -p path -v))
|
22
|
-
# Output:
|
23
|
-
# Called cast with args=[] opts={:path=>"path", :verbose=>true}
|
24
|
-
|
25
|
-
output *Cl.run(*%w(opts --path path --verbose))
|
26
|
-
# Output:
|
27
|
-
# Called cast with args=[] opts={:path=>"path", :verbose=>true}
|
28
|
-
|
29
|
-
output *Cl.run(*%w(opts one -p path two -v three))
|
30
|
-
# Output:
|
31
|
-
# Called cast with args=["one", "two", "three"] opts={:path=>"path", :verbose=>true}
|
32
|
-
|
data/examples/args/required.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'cl'
|
2
|
-
|
3
|
-
class Required < Cl::Cmd
|
4
|
-
arg :one, required: true
|
5
|
-
arg :two
|
6
|
-
|
7
|
-
def run
|
8
|
-
[self.registry_key, one: one, two: two]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def output(cmd, args)
|
13
|
-
args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
|
14
|
-
puts "Called #{cmd} with #{args}"
|
15
|
-
end
|
16
|
-
|
17
|
-
output *Cl.run(*%w(required one two))
|
18
|
-
# Output:
|
19
|
-
# Called required with one="one" two="two"
|
20
|
-
|
21
|
-
output *Cl.run(*%w(required one))
|
22
|
-
# Output:
|
23
|
-
# Called required with one="one" two=nil
|
24
|
-
|
25
|
-
output *Cl.run(*%w(required))
|
26
|
-
# Output:
|
27
|
-
# Missing arguments (given: 0, required: 1)
|
28
|
-
#
|
29
|
-
# Usage: args.rb required one [two]
|
30
|
-
|
31
|
-
output *Cl.run(*%w(required one two three))
|
32
|
-
# Output:
|
33
|
-
# Too many arguments (given: 3, allowed: 2)
|
34
|
-
#
|
35
|
-
# Usage: args.rb required one [two]
|
data/examples/args/splat.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'cl'
|
2
|
-
|
3
|
-
class SplatLeft < Cl::Cmd
|
4
|
-
register 'splat:left'
|
5
|
-
|
6
|
-
arg :one, type: :array
|
7
|
-
args :two, :three
|
8
|
-
|
9
|
-
def run
|
10
|
-
[self.registry_key, one: one, two: two, three: three]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class SplatMiddle < Cl::Cmd
|
15
|
-
register 'splat:middle'
|
16
|
-
|
17
|
-
arg :one
|
18
|
-
arg :two, type: :array
|
19
|
-
arg :three
|
20
|
-
|
21
|
-
def run
|
22
|
-
[self.registry_key, one: one, two: two, three: three]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class SplatRight < Cl::Cmd
|
27
|
-
register 'splat:right'
|
28
|
-
|
29
|
-
args :one, :two
|
30
|
-
arg :three, type: :array
|
31
|
-
|
32
|
-
def run
|
33
|
-
[self.registry_key, one: one, two: two, three: three]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def output(cmd, args)
|
38
|
-
args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
|
39
|
-
puts "Called #{cmd} with #{args}"
|
40
|
-
end
|
41
|
-
|
42
|
-
output *Cl.run(*%w(splat left foo bar baz buz))
|
43
|
-
# Output:
|
44
|
-
# Called splat:left with one=["foo", "bar"] two="baz" three="buz"
|
45
|
-
|
46
|
-
output *Cl.run(*%w(splat middle foo bar baz buz))
|
47
|
-
# Output:
|
48
|
-
# Called splat:middle with one="foo" two=["bar", "baz"] three="buz"
|
49
|
-
|
50
|
-
output *Cl.run(*%w(splat right foo bar baz buz))
|
51
|
-
# Output:
|
52
|
-
# Called splat:middle with one="foo" two="bar" three=["baz", "buz"]
|
data/examples/gem.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'cl'
|
2
|
-
|
3
|
-
module Gem
|
4
|
-
module Release
|
5
|
-
module Cmds
|
6
|
-
class Release < Cl::Cmd
|
7
|
-
arg :gemspec
|
8
|
-
|
9
|
-
opt '-h', '--host HOST' do |value|
|
10
|
-
opts[:host] = value
|
11
|
-
end
|
12
|
-
|
13
|
-
opt '-k', '--key KEY' do |value|
|
14
|
-
opts[:key] = value
|
15
|
-
end
|
16
|
-
|
17
|
-
opt '-q', '--quiet' do
|
18
|
-
opts[:version] = true
|
19
|
-
end
|
20
|
-
|
21
|
-
def run
|
22
|
-
[self.registry_key, args, opts]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Bump < Cl::Cmd
|
27
|
-
OPTS = {
|
28
|
-
commit: true
|
29
|
-
}
|
30
|
-
|
31
|
-
opt '-v', '--version VERSION', 'the version to bump to [1.1.1|major|minor|patch|pre|rc|release]' do |value|
|
32
|
-
opts[:version] = value
|
33
|
-
end
|
34
|
-
|
35
|
-
opt '--no-commit', 'bump the version, but do not commit' do
|
36
|
-
opts[:commit] = false
|
37
|
-
end
|
38
|
-
|
39
|
-
def run
|
40
|
-
[self.registry_key, args, opts]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
Cl.runner = :multi
|
48
|
-
Cl.run(*%w(help))
|
49
|
-
puts
|
50
|
-
|
51
|
-
# Type "gem.rb help COMMAND [SUBCOMMAND]" for more details:
|
52
|
-
#
|
53
|
-
# gem.rb release [gemspec] [options]
|
54
|
-
# gem.rb bump [options]
|
55
|
-
|
56
|
-
Cl.run(*%w(help release))
|
57
|
-
puts
|
58
|
-
|
59
|
-
# Usage: gem.rb release [gemspec] [options]
|
60
|
-
#
|
61
|
-
# -h --host HOST
|
62
|
-
# -k --key KEY
|
63
|
-
# -q --quiet
|
64
|
-
|
65
|
-
Cl.run(*%w(help bump))
|
66
|
-
puts
|
67
|
-
|
68
|
-
# Usage: gem.rb bump [options]
|
69
|
-
#
|
70
|
-
# -v --version VERSION # the version to bump to [1.1.1|major|minor|patch|pre|rc|release]
|
71
|
-
# --no-commit # bump the version, but do not commit
|
72
|
-
|
73
|
-
cmds = Cl.run(*%w(bump -v 1.1.1 release foo.gemspec -h host -k key -q))
|
74
|
-
puts 'Commands run:'
|
75
|
-
cmds.each do |(cmd, args, opts)|
|
76
|
-
puts "#{cmd} with args=#{args} opts=#{opts}"
|
77
|
-
end
|
78
|
-
|
79
|
-
# Commands run:
|
80
|
-
# bump with args=[] opts={:version=>"1.1.1"}
|
81
|
-
# release with args=["foo.gemspec"] opts={:host=>"host", :key=>"key", :version=>true}
|
data/examples/heroku.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'cl'
|
2
|
-
|
3
|
-
module Heroku
|
4
|
-
module Apps
|
5
|
-
class Create < Cl::Cmd
|
6
|
-
register 'apps:create'
|
7
|
-
|
8
|
-
arg :name, required: true
|
9
|
-
|
10
|
-
opt '-o', '--org ORG' do |value|
|
11
|
-
opts[:org] = value
|
12
|
-
end
|
13
|
-
|
14
|
-
def run; [registry_key, args, opts] end
|
15
|
-
end
|
16
|
-
|
17
|
-
class List < Cl::Cmd
|
18
|
-
register 'apps:info'
|
19
|
-
|
20
|
-
opt '-a', '--app APP' do |value|
|
21
|
-
opts[:app] = value
|
22
|
-
end
|
23
|
-
|
24
|
-
def run; [registry_key, args, opts] end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def output(cmd, args, opts)
|
30
|
-
puts "Called #{cmd} with args=#{args} opts=#{opts}"
|
31
|
-
end
|
32
|
-
|
33
|
-
output *Cl.run(*%w(apps:create name -o org))
|
34
|
-
# Called apps:create with args=["name"] opts={:org=>"org"}
|
35
|
-
|
36
|
-
output *Cl.run(*%w(apps create name -o org))
|
37
|
-
# Called apps:create with args=["name"] opts={:org=>"org"}
|
38
|
-
|
39
|
-
output *Cl.run(*%w(apps:info -a app))
|
40
|
-
# Called apps:create with args=["app"] opts={}
|
41
|
-
|
data/lib/cl/format/cmd.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'cl/format/table'
|
2
|
-
require 'cl/format/usage'
|
3
|
-
|
4
|
-
module Cl
|
5
|
-
class Format
|
6
|
-
class Cmd < Struct.new(:cmd)
|
7
|
-
def format
|
8
|
-
[banner, Table.new(opts).format].join("\n")
|
9
|
-
end
|
10
|
-
|
11
|
-
def banner
|
12
|
-
banner = []
|
13
|
-
banner << "#{cmd.purpose}\n" if cmd.purpose
|
14
|
-
banner << "Usage: #{Usage.new(cmd).format}\n"
|
15
|
-
banner
|
16
|
-
end
|
17
|
-
|
18
|
-
def opts
|
19
|
-
cmd.opts.map do |opts, block|
|
20
|
-
comment = opts.detect { |opt| !opt?(opt) }
|
21
|
-
opts = opts.select { |opt| opt?(opt) }
|
22
|
-
[opts.sort_by(&:size).join(' '), comment]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def opt?(str)
|
27
|
-
str.start_with?('-')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/cl/format/list.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'cl/format/table'
|
2
|
-
require 'cl/format/usage'
|
3
|
-
|
4
|
-
module Cl
|
5
|
-
class Format
|
6
|
-
class List < Struct.new(:cmds)
|
7
|
-
HEAD = %(Type "#{$0.split('/').last} help COMMAND [SUBCOMMAND]" for more details:\n)
|
8
|
-
|
9
|
-
def format
|
10
|
-
[HEAD, Format::Table.new(list).format].join("\n")
|
11
|
-
end
|
12
|
-
|
13
|
-
def list
|
14
|
-
cmds.map { |cmd| format_cmd(cmd) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def format_cmd(cmd)
|
18
|
-
["#{Usage.new(cmd).format}", cmd.purpose]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/cl/format/table.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Cl
|
2
|
-
class Format
|
3
|
-
class Table < Struct.new(:data, :separator)
|
4
|
-
def format
|
5
|
-
rows.join("\n")
|
6
|
-
end
|
7
|
-
|
8
|
-
def rows
|
9
|
-
rows = data.map { |lft, rgt| [lft.ljust(width), rgt] }
|
10
|
-
rows = rows.map { |lft, rgt| "#{lft} #{"# #{rgt}" if rgt}".strip }
|
11
|
-
rows.map(&:strip)
|
12
|
-
end
|
13
|
-
|
14
|
-
def width
|
15
|
-
@width ||= data.map(&:first).max_by(&:size).size
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/cl/options.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
|
-
module Cl
|
4
|
-
class Options < OptionParser
|
5
|
-
attr_reader :opts
|
6
|
-
|
7
|
-
def initialize(opts, args)
|
8
|
-
@opts = {}
|
9
|
-
super { opts.each { |args, block| on(*args) { |*args| instance_exec(*args, &block) } } }
|
10
|
-
parse!(args)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/cl/registry.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Cl
|
2
|
-
class << self
|
3
|
-
def []=(key, object)
|
4
|
-
registry[key.to_sym] = object
|
5
|
-
end
|
6
|
-
|
7
|
-
def [](key)
|
8
|
-
key && registry[key.to_sym]
|
9
|
-
end
|
10
|
-
|
11
|
-
def cmds
|
12
|
-
registry.values
|
13
|
-
end
|
14
|
-
|
15
|
-
def registry
|
16
|
-
@registry ||= {}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module Registry
|
21
|
-
class << self
|
22
|
-
def included(const)
|
23
|
-
const.send(:extend, ClassMethods)
|
24
|
-
const.send(:include, InstanceMethods)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module ClassMethods
|
29
|
-
attr_reader :registry_key
|
30
|
-
|
31
|
-
def [](key)
|
32
|
-
Cl[key.to_sym]
|
33
|
-
end
|
34
|
-
|
35
|
-
def register(key)
|
36
|
-
Cl[key] = self
|
37
|
-
@registry_key = key.to_sym
|
38
|
-
end
|
39
|
-
|
40
|
-
def underscore(string)
|
41
|
-
string.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
42
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
43
|
-
downcase
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module InstanceMethods
|
48
|
-
def registry_key
|
49
|
-
self.class.registry_key
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|