Sha256: fbad44ad22ba4599c442448aa10d8baa45d7fc9709aca98ff6597ae41575b0c0

Contents?: true

Size: 738 Bytes

Versions: 5

Compression:

Stored size: 738 Bytes

Contents

module Synchronisable
  # Provides a set of helper methods
  # to describe user input.
  #
  # @api private
  #
  # @see Synchronisable::InputParser
  class InputDescriptor
    attr_reader :data

    def initialize(data)
      @data = data
    end

    def empty?
      @data.blank?
    end

    def remote_id?
      @data.is_a?(String)
    end

    def local_id?
      @data.is_a?(Integer)
    end

    def array_of_ids?
       enumerable? && (
        first_element.is_a?(String) ||
        first_element.is_a?(Integer)
      )
    end

    def element_class
      first_element.try(:class)
    end

    private

    def first_element
      @data.try(:first)
    end

    def enumerable?
      @data.is_a?(Enumerable)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
synchronisable-1.0.4 lib/synchronisable/input_descriptor.rb
synchronisable-1.0.3 lib/synchronisable/input_descriptor.rb
synchronisable-1.0.2 lib/synchronisable/input_descriptor.rb
synchronisable-1.0.1 lib/synchronisable/input_descriptor.rb
synchronisable-1.0.0 lib/synchronisable/input_descriptor.rb