Class: Caml::Command
- Inherits:
-
Object
- Object
- Caml::Command
- Defined in:
- lib/caml/caml.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#execute ⇒ Object
readonly
Returns the value of attribute execute.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #dispatcher ⇒ Object
- #executor ⇒ Object
-
#initialize(options = {}) ⇒ Command
constructor
A new instance of Command.
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Command
Returns a new instance of Command.
33 34 35 36 37 38 39 40 |
# File 'lib/caml/caml.rb', line 33 def initialize( = {}) @name = ['name'] @desc = ['desc'] @aliases = ['aliases'] @args = ['args'] @opts = ['opts'] @execute = ['execute'] end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
31 32 33 |
# File 'lib/caml/caml.rb', line 31 def aliases @aliases end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
31 32 33 |
# File 'lib/caml/caml.rb', line 31 def args @args end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
31 32 33 |
# File 'lib/caml/caml.rb', line 31 def desc @desc end |
#execute ⇒ Object (readonly)
Returns the value of attribute execute.
31 32 33 |
# File 'lib/caml/caml.rb', line 31 def execute @execute end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/caml/caml.rb', line 31 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
31 32 33 |
# File 'lib/caml/caml.rb', line 31 def opts @opts end |
Instance Method Details
#dispatcher ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/caml/caml.rb', line 42 def dispatcher if opts.empty? executor else first_clause = "if options[:#{opts.first.name.to_sym}]\nexecute { \"#{opts.first.execute}\" }\n" # else_clause = directive.execute.nil? ? "#\n" : "else\nexecute { \"#{wrap(directive.execute).join(';')}\" }\nend" # clauses = directive.options.drop(1).map { |option| "elsif options[:#{option.name.to_sym}]\nexecute { \"#{wrap(option.execute).join(';')}\" }\n" }.join # dispatcher = first_clause + clauses + else_clause puts first_clause executor end end |
#executor ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/caml/caml.rb', line 55 def executor if execute.respond_to?(:join) <<-EOS execute do <<-COMMANDS #{execute.join("\n")} COMMANDS end EOS else "execute { \"#{execute}\" }\n" end end |
#to_s ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/caml/caml.rb', line 69 def to_s descriptor = "desc '#{name}', '#{desc}'\n" = opts.empty? ? '' : opts.join("\n") + "\n" signature = "def #{name}\n" # TODO: args close_scope = "end\n" descriptor + + signature + executor + close_scope end |