class AttrStatements::Attribute

Constants

OPTIONS

Attributes

class_type[RW]
key[RW]
options[RW]

Public Class Methods

new(key, class_type, options = {}) click to toggle source
# File lib/attr_statements/attribute.rb, line 27
def initialize(key, class_type, options = {})
  raise ArgumentError, ':options must be a Hash' unless options.is_a?(Hash)

  self.key        = key.to_sym
  self.class_type = class_type.is_a?(String) ? Object.const_get(class_type) : class_type
  self.options    = options.with_indifferent_access.slice(*Validation::VALIDATORS)
end

Public Instance Methods

length() click to toggle source
# File lib/attr_statements/attribute.rb, line 14
def length
  options.fetch(:length) { {} }
end
presence?() click to toggle source
# File lib/attr_statements/attribute.rb, line 10
def presence?
  options[:presence] == true
end