# File lib/bronze/entities/attributes/metadata.rb, line 66 def primary_key? !!@options[:primary_key] end
class Bronze::Entities::Attributes::Metadata
Data class that characterizes an entity attribute and allows for reflection on its properties and options.
Attributes
@return [String, Symbol] the name of the attribute.
@return [Hash] additional options for the attribute.
@return [String, Symbol] the name of the attribute's reader method.
@return [Class] the type of the attribute.
@return [String, Symbol] the name of the attribute's writer method.
Public Class Methods
@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
@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
@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
@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
@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
@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
@return [Boolean] true if the attribute is a primary key, otherwise false.
@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
@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
@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