class HecksApplication::Commands::Create

Create a resource

Attributes

args[RW]
domain_module[RW]
errors[RW]
id[RW]
repository[RW]
repository_result[R]
result[RW]

Public Class Methods

new(args:, repository:, domain_module:, validator: HecksApplication::Validator) click to toggle source
# File lib/commands/create.rb, line 8
def initialize(args:, repository:, domain_module:, validator: HecksApplication::Validator)
  @repository      = repository
  @args            = args
  @errors          = {}
  @validator       = validator
  @domain_module   = domain_module
end

Public Instance Methods

call() click to toggle source
# File lib/commands/create.rb, line 16
def call
  validate
  create
  self
end
name() click to toggle source
# File lib/commands/create.rb, line 26
def name
  self.class.to_s.split('::').last.underscore
end
to_h() click to toggle source
# File lib/commands/create.rb, line 22
def to_h
  { errors: errors, id: repository_result, args: args }
end

Private Instance Methods

create() click to toggle source
# File lib/commands/create.rb, line 38
def create
  return if @errors.count.positive?
  @id = args[:id]
  repository.create(args)
end
validate() click to toggle source
# File lib/commands/create.rb, line 44
def validate
  return if @validator.nil?
  @errors = @validator.new(command: self).call.errors
end