bales 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fb40f18edf38481a779d05e661167b9a504577f
4
- data.tar.gz: fdfb53af1b8ead967df753d0e03c332c10ffec3f
3
+ metadata.gz: 3697a0dc2411e2fed3dc7bacbd03a6d33c4ce785
4
+ data.tar.gz: d5aed1d5f97a63e0505ad77de3199be86b90a7dd
5
5
  SHA512:
6
- metadata.gz: 08f36ccf3b1ca492be4d60d7881add98f74e9f3732491e0041fe8280cb2e4d61b2ca9817a1086c3e6f5338bf2c535b5b6a04f49346552c3edda00fe0de8f41f7
7
- data.tar.gz: 4f86ed0b34ad824ea2bcab12100c1bfaa2fa921d8a7a3213ba9fb805df1375221cf7954c4bef6182bb546c2eac5b5be08950d13f6a51ce901cb0fcd686726fd1
6
+ metadata.gz: f15a4c35d75271d03d3e22b503c8eae3e8c295e1f912e724249ec7195e375df32282a1899e059901e9f7396d911a7c6675e6497c6c8885e1b8265f5b22eb686c
7
+ data.tar.gz: 9a979f78d9de61e06e719bd12951c356a8d935c38fef170f9c8ed05815a6b13e09bef24aa7b55cb7f091f1235c464d0e81762f9ea489b51713eceec83f72a531
@@ -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=nil, **opts, &code)
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
- const = eval(const_name)
39
+ base = eval(const_name)
41
40
  else
42
- const = base_name.const_set('Command', Class.new(opts[:parent]))
41
+ base = base_name.const_set('Command', Class.new(parent))
43
42
  end
44
43
 
45
- unless name.nil?
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
@@ -1,3 +1,3 @@
1
1
  module Bales
2
- VERSION="0.0.3"
2
+ VERSION="0.0.4"
3
3
  end
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.3
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-07-27 00:00:00.000000000 Z
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: