Sha256: b41cd3f27abc2be1f305444943c9c89166c956eff458caddaa76f10c04f9cda2

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

module Arpa
  module Services
    module Resources
      module Create
        class ResourceCreator

          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

          def resource_instance(resourceable)
            resource = Arpa::Entities::Resource.new(full_name: resourceable.to_s)
            resource.build_correct_name
            resource
          end

          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

          def finder_repo
            @finder_repo ||= Arpa::Repositories::Resources::Finder.new
          end

          def creator_repo
            @creator_repo ||= Arpa::Repositories::Resources::Creator.new
          end

        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
arpa-0.2.0 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.1.0 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.9 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.8 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.7 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.6 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.5 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.4 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.3 lib/arpa/services/resources/create/resource_creator.rb
arpa-0.0.2 lib/arpa/services/resources/create/resource_creator.rb