Class: Rufio::DslCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/rufio/dsl_command.rb

Overview

DSLで定義されたコマンドを表すクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, script: nil, description: "", interpreter: nil, ruby_block: nil, shell_command: nil) ⇒ DslCommand

コマンドを初期化する

Parameters:

  • name (String)

    コマンド名

  • script (String, nil) (defaults to: nil)

    スクリプトパス

  • description (String) (defaults to: "")

    コマンドの説明

  • interpreter (String, nil) (defaults to: nil)

    インタープリタ(nilの場合は自動検出)

  • ruby_block (Proc, nil) (defaults to: nil)

    inline Rubyブロック

  • shell_command (String, nil) (defaults to: nil)

    inline シェルコマンド



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

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/rufio/dsl_command.rb', line 6

def description
  @description
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/rufio/dsl_command.rb', line 6

def errors
  @errors
end

#interpreterObject (readonly)

Returns the value of attribute interpreter.



6
7
8
# File 'lib/rufio/dsl_command.rb', line 6

def interpreter
  @interpreter
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rufio/dsl_command.rb', line 6

def name
  @name
end

#ruby_blockObject (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

#scriptObject (readonly)

Returns the value of attribute script.



6
7
8
# File 'lib/rufio/dsl_command.rb', line 6

def script
  @script
end

#shell_commandObject (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_typeSymbol

コマンドタイプを返す

Returns:

  • (Symbol)

    :ruby, :shell, :script のいずれか



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_argsArray<String>

実行用の引数配列を返す

Returns:

  • (Array<String>)
    インタープリタ, スクリプトパス


50
51
52
# File 'lib/rufio/dsl_command.rb', line 50

def to_execution_args
  [@interpreter, @script]
end

#to_hHash

ハッシュ表現を返す

Returns:

  • (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

コマンドが有効かどうかを検証する

Returns:

  • (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