Class: Rufio::DslCommand
- Inherits:
-
Object
- Object
- Rufio::DslCommand
- Defined in:
- lib/rufio/dsl_command.rb
Overview
DSLで定義されたコマンドを表すクラス
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#interpreter ⇒ Object
readonly
Returns the value of attribute interpreter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ruby_block ⇒ Object
readonly
Returns the value of attribute ruby_block.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#shell_command ⇒ Object
readonly
Returns the value of attribute shell_command.
Instance Method Summary collapse
-
#command_type ⇒ Symbol
コマンドタイプを返す.
-
#initialize(name:, script: nil, description: "", interpreter: nil, ruby_block: nil, shell_command: nil) ⇒ DslCommand
constructor
コマンドを初期化する.
-
#to_execution_args ⇒ Array<String>
実行用の引数配列を返す.
-
#to_h ⇒ Hash
ハッシュ表現を返す.
-
#valid? ⇒ Boolean
コマンドが有効かどうかを検証する.
Constructor Details
#initialize(name:, script: nil, description: "", interpreter: nil, ruby_block: nil, shell_command: nil) ⇒ DslCommand
コマンドを初期化する
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rufio/dsl_command.rb', line 16 def initialize(name:, script: nil, description: "", interpreter: nil, ruby_block: nil, shell_command: nil) @name = name.to_s @script = script ? normalize_path(script.to_s) : nil @description = description.to_s @interpreter = interpreter || auto_resolve_interpreter @ruby_block = ruby_block @shell_command = shell_command @errors = [] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/rufio/dsl_command.rb', line 6 def description @description end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/rufio/dsl_command.rb', line 6 def errors @errors end |
#interpreter ⇒ Object (readonly)
Returns the value of attribute interpreter.
6 7 8 |
# File 'lib/rufio/dsl_command.rb', line 6 def interpreter @interpreter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rufio/dsl_command.rb', line 6 def name @name end |
#ruby_block ⇒ Object (readonly)
Returns the value of attribute ruby_block.
7 8 9 |
# File 'lib/rufio/dsl_command.rb', line 7 def ruby_block @ruby_block end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
6 7 8 |
# File 'lib/rufio/dsl_command.rb', line 6 def script @script end |
#shell_command ⇒ Object (readonly)
Returns the value of attribute shell_command.
7 8 9 |
# File 'lib/rufio/dsl_command.rb', line 7 def shell_command @shell_command end |
Instance Method Details
#command_type ⇒ Symbol
コマンドタイプを返す
29 30 31 32 33 34 35 36 37 |
# File 'lib/rufio/dsl_command.rb', line 29 def command_type if @ruby_block :ruby elsif @shell_command :shell else :script end end |
#to_execution_args ⇒ Array<String>
実行用の引数配列を返す
50 51 52 |
# File 'lib/rufio/dsl_command.rb', line 50 def to_execution_args [@interpreter, @script] end |
#to_h ⇒ Hash
ハッシュ表現を返す
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rufio/dsl_command.rb', line 56 def to_h hash = { name: @name, script: @script, description: @description, interpreter: @interpreter } hash[:has_ruby_block] = true if @ruby_block hash[:shell_command] = @shell_command if @shell_command hash end |
#valid? ⇒ Boolean
コマンドが有効かどうかを検証する
41 42 43 44 45 46 |
# File 'lib/rufio/dsl_command.rb', line 41 def valid? @errors = [] validate_name validate_execution_source @errors.empty? end |