Sha256: 7397535c83ad7e1f2074ffefd5bf6ae0162ac570762c373ce95b40045234b1bb

Contents?: true

Size: 1.94 KB

Versions: 23

Compression:

Stored size: 1.94 KB

Contents

module Eco::API::UseCases::GraphQL::Helpers::Location
  module Base
    module ClassificationsParser
      include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv

      private

      # @note
      #   1. It returns `nil` unless there are classifications defined
      #   2. If the value is wrong, it warns and returns `nil`
      def to_classification(value)
        return nil unless node_classifications?
        raise ArgumentError, "Expecting a single element. Given: #{value.class}" if value.is_a?(Enumerator)
        return nil unless value.is_a?(String)

        node_classifications.to_id(value).tap do |type|
          unknown_clasification!(value) unless type
        end
      end

      def to_classification_ids(values)
        values = [values].flatten unless values.is_a?(Array)
        values.compact.map {|val| to_classification(val)}.compact
      end

      # @note
      #   1. It returns `nil` unless there are classifications defined
      #   2. If the value is wrong, it warns and returns `nil`
      def to_classification_name(value)
        return nil unless node_classifications?
        raise ArgumentError, "Expecting a single element. Given: #{value.class}" if value.is_a?(Enumerator)
        return nil unless value.is_a?(String)

        node_classifications.to_name(value) do |name|
          unknown_clasification!(value) unless name
        end
      end

      def node_classifications?
        node_classifications.any?
      end

      def node_classifications
        @node_classifications ||= session.node_classifications
      end

      def unknown_clasification!(value)
        return if unknown_classifications.include?(value)
        unknown_classifications << value
        log(:warn) {
          "Unknown location node classification '#{value}'"
        }
      end

      def unknown_classifications
        @unknown_classifications ||= []
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
eco-helpers-3.0.4 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-3.0.3 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-3.0.2 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-3.0.1 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-3.0.0 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.25 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.24 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.23 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.22 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.21 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.20 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.19 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.18 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.17 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.16 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.15 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.14 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.13 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.12 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb
eco-helpers-2.7.4 lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb