class Arpa::Services::Resources::Create::ResourceCreator

Public Instance Methods

create(resourceable) click to toggle source
# File lib/arpa/services/resources/create/resource_creator.rb, line 6
def create(resourceable)
  resource = resource_instance(resourceable)

  resource_found = finder_repo.by_full_name(resource.full_name)
  return resource_found if resource_found

  validate_resource(resource)
  creator_repo.create(resource)
end

Private Instance Methods

creator_repo() click to toggle source
# File lib/arpa/services/resources/create/resource_creator.rb, line 33
def creator_repo
  @creator_repo ||= Arpa::Repositories::Resources::Creator.new
end
finder_repo() click to toggle source
# File lib/arpa/services/resources/create/resource_creator.rb, line 29
def finder_repo
  @finder_repo ||= Arpa::Repositories::Resources::Finder.new
end
resource_instance(resourceable) click to toggle source
# File lib/arpa/services/resources/create/resource_creator.rb, line 18
def resource_instance(resourceable)
  resource = Arpa::Entities::Resource.new(full_name: resourceable.to_s)
  resource.build_correct_name
  resource
end
validate_resource(resource) click to toggle source
# File lib/arpa/services/resources/create/resource_creator.rb, line 24
def validate_resource(resource)
  validator = Arpa::Validators::ResourceValidator.new(resource)
  raise Arpa::Exceptions::RecordInvalid.new(message: validator.errors.messages, errors: validator.errors) unless validator.valid?
end