Sha256: daf2491166338a8beddc4665004a99c417d686985f392ffcdf98929f21d1168c

Contents?: true

Size: 785 Bytes

Versions: 5

Compression:

Stored size: 785 Bytes

Contents

# A helper to ensure `object` implements the concept `as`
class GraphQL::Schema::ImplementationValidator
  attr_reader :object, :errors, :implementation_as
  def initialize(object, as:, errors:)
    @object = object
    @implementation_as = as
    @errors = errors
  end

  # Ensure the object responds to `method_name`.
  # If `block_given?`, yield the return value of that method
  # If provided, use `as` in the error message, overriding class-level `as`.
  def must_respond_to(method_name, args: [], as: nil)
    if !object.respond_to?(method_name)
      local_as = as || implementation_as
      errors << "#{object.to_s} must respond to ##{method_name}(#{args.join(", ")}) to be a #{local_as}"
    elsif block_given?
      yield(object.public_send(method_name))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-0.6.0 lib/graphql/schema/implementation_validator.rb
graphql-0.5.0 lib/graph_ql/schema/implementation_validator.rb
graphql-0.4.0 lib/graph_ql/schema/implementation_validator.rb
graphql-0.3.0 lib/graph_ql/schema/implementation_validator.rb
graphql-0.2.0 lib/graph_ql/schema/implementation_validator.rb