Sha256: 92fd6fbe90eec417d21ea93d408cf696245518d5029ceeafb722fdd9eb2ed37d

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

module Troo
  module Remote
    module Persistence
      class Board
        class << self
          # @param  [String]
          # @param  [String, NilClass]
          # @return []
          def with(name, description = nil)
            new(name, description).perform
          end
        end

        # @param  [String]
        # @param  [String, NilClass]
        # @return []
        def initialize(name, description = nil)
          @name        = name
          @description = description
        end

        # @return []
        def perform
          create_local
        end

        private

        attr_reader :name, :description

        def create_local
          return Troo::Persistence::Local
            .with_collection(resource).first if any?
          false
        end

        def any?
          resource.any?
        end

        def resource
          @resource ||= API::Client.perform(parameters)
        end

        def parameters
          {
            verb:          :post,
            endpoint:      :create_board,
            interpolation: {},
            query:         query,
            model:         Remote::Board
          }
        end

        def query
          {
            name: name,
            desc: description
          }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.11 lib/troo/remote/persistence/board.rb