Class: Inspector::AttributeMetadata

Inherits:
Object
  • Object
show all
Includes:
Metadata
Defined in:
lib/inspector/attribute_metadata.rb

Instance Attribute Summary collapse

Attributes included from Metadata

#children_metadata, #constraints, #type

Instance Method Summary collapse

Methods included from Metadata

#attribute, #attribute_metadatas, #children, #each_item, #property, #property_metadatas, #should, #should_not

Methods included from Constraints

#be_email, #be_empty, #be_false, #be_true, #eq, #have, #have_at_least, #have_at_most, #method_missing, #validate

Methods included from Constraint

#negate!, #positive?, #validator

Constructor Details

#initialize(type, attribute_name) ⇒ AttributeMetadata

Returns a new instance of AttributeMetadata.



7
8
9
10
# File 'lib/inspector/attribute_metadata.rb', line 7

def initialize(type, attribute_name)
  @attribute_name = attribute_name.to_sym
  super(type)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Inspector::Constraints

Instance Attribute Details

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



5
6
7
# File 'lib/inspector/attribute_metadata.rb', line 5

def attribute_name
  @attribute_name
end

Instance Method Details

#attribute_value(object) ⇒ Object



12
13
14
15
16
17
# File 'lib/inspector/attribute_metadata.rb', line 12

def attribute_value(object)
  object.__send__(@attribute_name)
rescue NoMethodError
  raise "metadata for #{@type.inspect} contains attribute metadata, however " +
        "#{object.inspect}.#{@attribute_name.inspect} is not defined"
end