Class: Moku::Command::Command

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

Overview

Represetns a command within Moku

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_name:, user:, logger: nil, instance_repo: nil) ⇒ Command

Returns a new instance of Command.


10
11
12
13
14
15
# File 'lib/moku/command/command.rb', line 10

def initialize(instance_name:, user:, logger: nil, instance_repo: nil)
  @instance_name = instance_name
  @user = user
  @logger = logger || Moku.logger
  @instance_repo = instance_repo || Moku.instance_repo
end

Instance Attribute Details

#instance_nameObject (readonly)

Returns the value of attribute instance_name


8
9
10
# File 'lib/moku/command/command.rb', line 8

def instance_name
  @instance_name
end

#loggerObject (readonly)

Returns the value of attribute logger


8
9
10
# File 'lib/moku/command/command.rb', line 8

def logger
  @logger
end

#userObject (readonly)

Returns the value of attribute user


8
9
10
# File 'lib/moku/command/command.rb', line 8

def user
  @user
end

Instance Method Details

#actionObject


17
18
19
# File 'lib/moku/command/command.rb', line 17

def action
  :none
end

#authorized?Boolean

Returns:

  • (Boolean)

21
22
23
24
25
26
27
# File 'lib/moku/command/command.rb', line 21

def authorized?
  Moku.auth.authorized?(
    user: user || "nobody",
    entity: instance,
    action: action
  )
end

#instanceObject


29
30
31
32
33
# File 'lib/moku/command/command.rb', line 29

def instance
  @instance ||= instance_repo.find(instance_name)
rescue Errno::ENOENT
  raise ArgumentError, "The requested instance [#{instance_name}] doesn't exist"
end