Included Modules

Files

Virtus::Extensions::Methods

Public Instance Methods

attribute(name, type = nil, options = {}) click to toggle source

Defines an attribute on an object’s class or instance

@example

class Book
  include Virtus.model

  attribute :title,        String
  attribute :author,       String
  attribute :published_at, DateTime
  attribute :page_count,   Integer
  attribute :index                   # defaults to Object
end

@param [Symbol] name

the name of an attribute

@param [Class,Array,Hash,Axiom::Types::Type,String,Symbol] type

the type class of an attribute

@param [to_hash] options

the extra options hash

@return [self]

@see Attribute.build

@api public

# File lib/virtus/extensions.rb, line 63
def attribute(name, type = nil, options = {})
  assert_valid_name(name)
  attribute_set << Attribute.build(type, options.merge(:name => name))
  self
end
values(&block) click to toggle source

@see Virtus.default_value

@api public

# File lib/virtus/extensions.rb, line 72
def values(&block)
  private :attributes= if instance_methods.include?(:attributes=)
  yield
  include(::Equalizer.new(*attribute_set.map(&:name)))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.