module Inspector::Metadata

Attributes

children_metadata[R]
constraints[R]
type[R]

Public Class Methods

new(type) click to toggle source
# File lib/inspector/metadata.rb, line 12
def initialize(type)
  @type = type
  @constraints = []
  @property_metadatas = {}
  @attribute_metadatas = {}
end

Public Instance Methods

attribute(name) { |attribute_metadatas| ... } click to toggle source
# File lib/inspector/metadata.rb, line 19
def attribute(name, &block)
  @attribute_metadatas[name] ||= AttributeMetadata.new(@type, name)
  if block_given?
    block.arity == 1 ? yield(@attribute_metadatas[name]) : @attribute_metadatas[name].instance_eval(&block)
  end
  @attribute_metadatas[name]
end
attribute_metadatas() click to toggle source
# File lib/inspector/metadata.rb, line 60
def attribute_metadatas
  @attribute_metadatas.values
end
children(object, &block) click to toggle source
# File lib/inspector/metadata.rb, line 68
def children(object, &block)
  object.each_with_index(&block)
rescue NoMethodError
  raise "metadata for #{@type.inspect} contains children metadata, however " +
        "#{object.inspect}.each_with_index is not defined"
end
each_item() { |children_metadata| ... } click to toggle source
# File lib/inspector/metadata.rb, line 35
def each_item(&block)
  @children_metadata ||= TypeMetadata.new(@type)
  if block_given?
    block.arity == 1 ? yield(@children_metadata) : @children_metadata.instance_eval(&block)
  end
  @children_metadata
end
property(name) { |property_metadatas| ... } click to toggle source
# File lib/inspector/metadata.rb, line 27
def property(name, &block)
  @property_metadatas[name] ||= PropertyMetadata.new(@type, name)
  if block_given?
    block.arity == 1 ? yield(@property_metadatas[name]) : @property_metadatas[name].instance_eval(&block)
  end
  @property_metadatas[name]
end
property_metadatas() click to toggle source
# File lib/inspector/metadata.rb, line 64
def property_metadatas
  @property_metadatas.values
end
should(constraint = nil) click to toggle source
# File lib/inspector/metadata.rb, line 43
def should(constraint = nil)
  return PositiveComparator.new(self) if constraint.nil?

  @constraints << constraint

  self
end
should_not(constraint = nil) click to toggle source
# File lib/inspector/metadata.rb, line 51
def should_not(constraint = nil)
  return NegativeComparator.new(self) if constraint.nil?

  constraint.negate!
  @constraints << constraint

  self
end