bales 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bales/application.rb +4 -25
- data/lib/bales/command.rb +30 -0
- data/lib/bales/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3697a0dc2411e2fed3dc7bacbd03a6d33c4ce785
|
4
|
+
data.tar.gz: d5aed1d5f97a63e0505ad77de3199be86b90a7dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f15a4c35d75271d03d3e22b503c8eae3e8c295e1f912e724249ec7195e375df32282a1899e059901e9f7396d911a7c6675e6497c6c8885e1b8265f5b22eb686c
|
7
|
+
data.tar.gz: 9a979f78d9de61e06e719bd12951c356a8d935c38fef170f9c8ed05815a6b13e09bef24aa7b55cb7f091f1235c464d0e81762f9ea489b51713eceec83f72a531
|
data/lib/bales/application.rb
CHANGED
@@ -32,37 +32,16 @@ module Bales
|
|
32
32
|
# Command should be a string corresponding to how the command will
|
33
33
|
# be invoked on the command-line; thus, a command with the class
|
34
34
|
# name +FooBar::Baz+ should be passed as "foo-bar baz".
|
35
|
-
def self.command(name
|
35
|
+
def self.command(name, parent: Bales::Command, &code)
|
36
36
|
const_name = "#{base_name.name}::Command"
|
37
|
-
opts[:parent] ||= Bales::Command
|
38
37
|
|
39
38
|
if eval("defined? #{const_name}") == "constant"
|
40
|
-
|
39
|
+
base = eval(const_name)
|
41
40
|
else
|
42
|
-
|
41
|
+
base = base_name.const_set('Command', Class.new(parent))
|
43
42
|
end
|
44
43
|
|
45
|
-
|
46
|
-
name
|
47
|
-
.to_s
|
48
|
-
.split(' ')
|
49
|
-
.map { |p| p
|
50
|
-
.downcase
|
51
|
-
.gsub('_','-')
|
52
|
-
.split('-')
|
53
|
-
.map { |pp| pp.capitalize }
|
54
|
-
.join }
|
55
|
-
.each do |part|
|
56
|
-
name = "#{const.name}::#{part}"
|
57
|
-
if const.const_defined? name
|
58
|
-
const = eval(name)
|
59
|
-
else
|
60
|
-
const = const.const_set(part, Class.new(opts[:parent]))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
const.instance_eval(&code) if block_given?
|
44
|
+
base.command(name, parent: parent, base: base, &code)
|
66
45
|
end
|
67
46
|
|
68
47
|
##
|
data/lib/bales/command.rb
CHANGED
@@ -87,6 +87,36 @@ module Bales
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
##
|
91
|
+
# Creates a new subcommand of the current command. Identical in
|
92
|
+
# usage to +Bales::Application.command+, the only significant
|
93
|
+
# difference being that +Bales::Command.command+ defines a command
|
94
|
+
# on its own scope instead of that of the application's root
|
95
|
+
# command. +Bales::Command.command+ also defaults to making
|
96
|
+
# subcommands' classes descendants of itself (unlike the
|
97
|
+
# application-level equivalent, which defaults to +Bales::Command+
|
98
|
+
# as the new subcommand's parent).
|
99
|
+
def self.command(name, parent: self, base: self, &code)
|
100
|
+
name
|
101
|
+
.to_s
|
102
|
+
.split(' ')
|
103
|
+
.map { |p| p
|
104
|
+
.downcase
|
105
|
+
.gsub('_','-')
|
106
|
+
.split('-')
|
107
|
+
.map { |pp| pp.capitalize }
|
108
|
+
.join }
|
109
|
+
.each do |part|
|
110
|
+
if base.const_defined? "#{base.name}::#{part}"
|
111
|
+
base = eval("#{base.name}::#{part}")
|
112
|
+
else
|
113
|
+
base = base.const_set(part, Class.new(parent))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
base.instance_eval(&code) if block_given?
|
118
|
+
end
|
119
|
+
|
90
120
|
##
|
91
121
|
# Assigns an action to this command. Said action is represented
|
92
122
|
# as a block, which should accept an array of arguments and a hash
|
data/lib/bales/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bales
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan S. Northrup
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A framework for building command-line applications
|
14
14
|
email:
|