module Virtus::Extensions::Methods

Private Class Methods

extended(descendant) click to toggle source

@api private

Calls superclass method
# File lib/virtus/extensions.rb, line 29
def self.extended(descendant)
  super
  descendant.extend(AttributeSet.create(descendant))
end

Public Instance Methods

allowed_writer_methods() click to toggle source

The list of writer methods that can be mass-assigned to in attributes=

@return [Set]

@api private

# File lib/virtus/extensions.rb, line 82
def allowed_writer_methods
  @allowed_writer_methods ||=
    begin
      allowed_writer_methods  = allowed_methods.grep(WRITER_METHOD_REGEXP).to_set
      allowed_writer_methods -= INVALID_WRITER_METHODS
      allowed_writer_methods.freeze
    end
end
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 62
def attribute(name, type = nil, options = {})
  assert_valid_name(name)
  attribute_set << Attribute.build(type, options.merge(:name => name))
  self
end
values() { || ... } click to toggle source

@see Virtus.default_value

@api public

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

Private Instance Methods

attribute_set() click to toggle source

Return an attribute set for that instance

@return [AttributeSet]

@api private

# File lib/virtus/extensions.rb, line 98
def attribute_set
  @attribute_set
end