class Bronze::Entities::Attributes::Metadata

Data class that characterizes an entity attribute and allows for reflection on its properties and options.

Attributes

name[R]

@return [String, Symbol] the name of the attribute.

options[R]

@return [Hash] additional options for the attribute.

reader_name[R]

@return [String, Symbol] the name of the attribute's reader method.

type[R]

@return [Class] the type of the attribute.

writer_name[R]

@return [String, Symbol] the name of the attribute's writer method.

Public Class Methods

new(name, type, options) click to toggle source

@param name [String, Symbol] The name of the attribute. @param type [Class] The type of the attribute. @param options [Hash] Additional options for the attribute.

# File lib/bronze/entities/attributes/metadata.rb, line 12
def initialize(name, type, options)
  @name        = name.intern
  @type        = type
  @options     = options
  @reader_name = name.intern
  @writer_name = "#{name}=".intern
end

Public Instance Methods

allow_nil?() click to toggle source

@return [Boolean] true if the attribute allows nil values, otherwise

false.
# File lib/bronze/entities/attributes/metadata.rb, line 37
def allow_nil?
  !!@options[:allow_nil]
end
default() click to toggle source

@return [Object] the default value for the attribute.

# File lib/bronze/entities/attributes/metadata.rb, line 42
def default
  val = @options[:default]

  val.is_a?(Proc) ? val.call : val
end
Also aliased as: default_value
default?() click to toggle source

@return [Boolean] true if the default value is set, otherwise false.

# File lib/bronze/entities/attributes/metadata.rb, line 50
def default?
  !@options[:default].nil?
end
default_transform?() click to toggle source

@return [Boolean] true if the attribute does not have a custom transform,

or if the transform is flagged as a default transform; otherwise false.
# File lib/bronze/entities/attributes/metadata.rb, line 56
def default_transform?
  !!@options[:default_transform] || !transform?
end
default_value()
Alias for: default
foreign_key?() click to toggle source

@return [Boolean] true if the attribute is a foreign key, otherwise false.

# File lib/bronze/entities/attributes/metadata.rb, line 61
def foreign_key?
  !!@options[:foreign_key]
end
primary_key?() click to toggle source

@return [Boolean] true if the attribute is a primary key, otherwise false.

# File lib/bronze/entities/attributes/metadata.rb, line 66
def primary_key?
  !!@options[:primary_key]
end
read_only?() click to toggle source

@return [Boolean] true if the attribute is read-only, otherwise false.

# File lib/bronze/entities/attributes/metadata.rb, line 71
def read_only?
  !!@options[:read_only]
end
transform() click to toggle source

@return [Bronze::Transform] the transform used to normalize and

denormalize the attribute.
# File lib/bronze/entities/attributes/metadata.rb, line 77
def transform
  @options[:transform]
end
transform?() click to toggle source

@return [Boolean] true if the attribute has a custom transform, otherwise

false.
# File lib/bronze/entities/attributes/metadata.rb, line 83
def transform?
  !!@options[:transform]
end