class ActiveModel::Attribute

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/active_model/attribute.rbs

class ActiveModel::Attribute
  def from_database: (String name, String? value_before_type_cast, ActiveModel::Type::String type, ?nil value) -> untyped
end

:nodoc:

def ==(other)

def ==(other)
  self.class == other.class &&
    name == other.name &&
    value_before_type_cast == other.value_before_type_cast &&
    type == other.type
end

def _original_value_for_database

def _original_value_for_database
  type.serialize(original_value)
end

def came_from_user?

def came_from_user?
  false
end

def changed?

def changed?
  changed_from_assignment? || changed_in_place?
end

def changed_from_assignment?

def changed_from_assignment?
  assigned? && type.changed?(original_value, value, value_before_type_cast)
end

def changed_in_place?

def changed_in_place?
  has_been_read? && type.changed_in_place?(original_value_for_database, value)
end

def encode_with(coder)

def encode_with(coder)
  coder["name"] = name
  coder["value_before_type_cast"] = value_before_type_cast unless value_before_type_cast.nil?
  coder["type"] = type if type
  coder["original_attribute"] = original_attribute if original_attribute
  coder["value"] = value if defined?(@value)
end

def forgetting_assignment

def forgetting_assignment
  with_value_from_database(value_for_database)
end

def from_database(name, value_before_type_cast, type, value = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def from_database: (String name, String? value_before_type_cast, ActiveModel::Type::String type, ?nil value) -> untyped

This signature was generated using 2 samples from 1 application.

def from_database(name, value_before_type_cast, type, value = nil)
  FromDatabase.new(name, value_before_type_cast, type, nil, value)
end

def from_user(name, value_before_type_cast, type, original_attribute = nil)

def from_user(name, value_before_type_cast, type, original_attribute = nil)
  FromUser.new(name, value_before_type_cast, type, original_attribute)
end

def has_been_read?

def has_been_read?
  defined?(@value)
end

def hash

def hash
  [self.class, name, value_before_type_cast, type].hash
end

def init_with(coder)

def init_with(coder)
  @name = coder["name"]
  @value_before_type_cast = coder["value_before_type_cast"]
  @type = coder["type"]
  @original_attribute = coder["original_attribute"]
  @value = coder["value"] if coder.map.key?("value")
end

def initialize(name, value_before_type_cast, type, original_attribute = nil, value = nil)

Use #from_database or #from_user
This method should not be called directly.
def initialize(name, value_before_type_cast, type, original_attribute = nil, value = nil)
  @name = name
  @value_before_type_cast = value_before_type_cast
  @type = type
  @original_attribute = original_attribute
  @value = value unless value.nil?
end

def initialize_dup(other)

def initialize_dup(other)
  if defined?(@value) && @value.duplicable?
    @value = @value.dup
  end
end

def initialized?

def initialized?
  true
end

def null(name)

def null(name)
  Null.new(name)
end

def original_value

def original_value
  if assigned?
    original_attribute.original_value
  else
    type_cast(value_before_type_cast)
  end
end

def original_value_for_database

def original_value_for_database
  if assigned?
    original_attribute.original_value_for_database
  else
    _original_value_for_database
  end
end

def serializable?(&block)

def serializable?(&block)
  type.serializable?(value, &block)
end

def type_cast(*)

def type_cast(*)
  raise NotImplementedError
end

def uninitialized(name, type)

def uninitialized(name, type)
  Uninitialized.new(name, type)
end

def value

def value
  # `defined?` is cheaper than `||=` when we get back falsy values
  @value = type_cast(value_before_type_cast) unless defined?(@value)
  @value
end

def value_for_database

def value_for_database
  type.serialize(value)
end

def with_cast_value(name, value_before_type_cast, type)

def with_cast_value(name, value_before_type_cast, type)
  WithCastValue.new(name, value_before_type_cast, type)
end

def with_cast_value(value)

def with_cast_value(value)
  self.class.with_cast_value(name, value, type)
end

def with_type(type)

def with_type(type)
  if changed_in_place?
    with_value_from_user(value).with_type(type)
  else
    self.class.new(name, value_before_type_cast, type, original_attribute)
  end
end

def with_value_from_database(value)

def with_value_from_database(value)
  self.class.from_database(name, value, type)
end

def with_value_from_user(value)

def with_value_from_user(value)
  type.assert_valid_value(value)
  self.class.from_user(name, value, type, original_attribute || self)
end