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