Class: Duple::Config::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/duple/config/command.rb

Overview

Represents a command that can be executed in the source or target environment.

Constant Summary collapse

SHELL =
'shell'
HEROKU =
'heroku'
VALID_TYPES =
[SHELL, HEROKU]
SOURCE =
'source'
TARGET =
'target'
VALID_SUBJECTS =
[SOURCE, TARGET]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash) ⇒ Command

Returns a new instance of Command.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/duple/config/command.rb', line 15

def initialize(config_hash)
  @command = config_hash['command']
  @type = config_hash['command_type']
  @subject = config_hash['subject']

  unless VALID_TYPES.include?(@type)
    raise ArgumentError.new("Invalid config: #{@type} is not a valid command type.")
  end

  unless VALID_SUBJECTS.include?(@subject)
    raise ArgumentError.new("Invalid config: #{@subject} is not a valid command subject.")
  end
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



13
14
15
# File 'lib/duple/config/command.rb', line 13

def command
  @command
end

#subjectObject

Returns the value of attribute subject.



13
14
15
# File 'lib/duple/config/command.rb', line 13

def subject
  @subject
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/duple/config/command.rb', line 13

def type
  @type
end

Instance Method Details

#heroku?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/duple/config/command.rb', line 37

def heroku?
  type == Duple::Config::Command::HEROKU
end

#shell?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/duple/config/command.rb', line 41

def shell?
  type == Duple::Config::Command::SHELL
end

#source?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/duple/config/command.rb', line 29

def source?
  subject == Duple::Config::Command::SOURCE
end

#target?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/duple/config/command.rb', line 33

def target?
  subject == Duple::Config::Command::TARGET
end