Class: Carrasco::Group
- Inherits:
-
Object
- Object
- Carrasco::Group
- Defined in:
- lib/carrasco/group.rb
Constant Summary collapse
- InvalidGroupError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#break_on_failure ⇒ Object
readonly
Returns the value of attribute break_on_failure.
-
#command_name ⇒ Object
readonly
Returns the value of attribute command_name.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#help ⇒ Object
readonly
Returns the value of attribute help.
Instance Method Summary collapse
-
#initialize(group_name, options = {}) ⇒ Group
constructor
A new instance of Group.
- #inject_into_class(klass) ⇒ Object
Constructor Details
#initialize(group_name, options = {}) ⇒ Group
Returns a new instance of Group.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/carrasco/group.rb', line 9 def initialize(group_name, = {}) = Thor::CoreExt::HashWithIndifferentAccess.new() @command_name = group_name @help = [:help] || command_name @description = [:description] || "description not given" @break_on_failure = [:break_on_failure] @break_on_failure = true if break_on_failure.nil? @commands = .fetch('commands') do raise InvalidGroupError, "Commands not provided for group '#{group_name}'" end end |
Instance Attribute Details
#break_on_failure ⇒ Object (readonly)
Returns the value of attribute break_on_failure.
7 8 9 |
# File 'lib/carrasco/group.rb', line 7 def break_on_failure @break_on_failure end |
#command_name ⇒ Object (readonly)
Returns the value of attribute command_name.
7 8 9 |
# File 'lib/carrasco/group.rb', line 7 def command_name @command_name end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
7 8 9 |
# File 'lib/carrasco/group.rb', line 7 def commands @commands end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/carrasco/group.rb', line 7 def description @description end |
#help ⇒ Object (readonly)
Returns the value of attribute help.
7 8 9 |
# File 'lib/carrasco/group.rb', line 7 def help @help end |
Instance Method Details
#inject_into_class(klass) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/carrasco/group.rb', line 21 def inject_into_class(klass) group = self klass.desc(help, description) klass.class_eval do define_method(group.command_name) do execute_commands(group.commands, group.break_on_failure) end end end |