class ActiveModel::LazyAttributeSet
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/active_model/attribute_set/builder.rbs class ActiveModel::LazyAttributeSet < ActiveModel::AttributeSet def fetch_value: (String name, ) -> String def initialize: (Hash values, Hash types, Hash additional_types, Hash default_attributes, ?Hash attributes, Hash attributes) -> void end
:nodoc:
def attributes
def attributes unless @materialized values.each_key { |key| self[key] } types.each_key { |key| self[key] } @materialized = true end @attributes end
def default_attribute(
def default_attribute( name, value_present = true, value = values.fetch(name) { value_present = false } ) type = additional_types.fetch(name, types[name]) if value_present @attributes[name] = Attribute.from_database(name, value, type, @casted_values[name]) elsif types.key?(name) if attr = default_attributes[name] @attributes[name] = attr.dup else @attributes[name] = Attribute.uninitialized(name, type) end else Attribute.null(name) end end
def fetch_value(name, &block)
Experimental RBS support (using type sampling data from the type_fusion
project).
def fetch_value: (String name, ) -> String
This signature was generated using 8 samples from 1 application.
def fetch_value(name, &block) if attr = @attributes[name] return attr.value(&block) end @casted_values.fetch(name) do value_present = true value = values.fetch(name) { value_present = false } if value_present type = additional_types.fetch(name, types[name]) @casted_values[name] = type.deserialize(value) else attr = default_attribute(name, value_present, value) attr.value(&block) end end end
def initialize(values, types, additional_types, default_attributes, attributes = {})
Experimental RBS support (using type sampling data from the type_fusion
project).
def initialize: ((id | Integer | gem_name | String | gem_version | String | receiver | String | method_name | String | location | String | type_fusion_version | String | application_name | String | source_ip | String | parameters | String | created_at | Time | updated_at | Time | return_value | String | id | Integer | gem_name | String | gem_version | String | receiver | String | method_name | String | location | String | type_fusion_version | String | application_name | String | source_ip | String | parameters | String | created_at | Time | updated_at | Time | return_value | NilClass) values, id | ActiveModel::Type::Integer | gem_name | ActiveModel::Type::String | gem_version | ActiveModel::Type::String | receiver | ActiveModel::Type::String | method_name | ActiveModel::Type::String | location | ActiveModel::Type::String | type_fusion_version | ActiveModel::Type::String | application_name | ActiveModel::Type::String | source_ip | ActiveModel::Type::String | parameters | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | created_at | ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter | updated_at | ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter | return_value | ActiveModel::Type::String types, 0 | ActiveModel::Type::Integer | 1 | ActiveModel::Type::String | 2 | ActiveModel::Type::String | 3 | ActiveModel::Type::String | 4 | ActiveModel::Type::String | 5 | ActiveModel::Type::String | 6 | ActiveModel::Type::String | 7 | ActiveModel::Type::String | 8 | ActiveModel::Type::String | 9 | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | 10 | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | 11 | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | 12 | ActiveModel::Type::String additional_types, id | ActiveModel::Attribute::FromDatabase default_attributes, ? attributes, attributes) -> void
This signature was generated using 5 samples from 1 application.
def initialize(values, types, additional_types, default_attributes, attributes = {}) super(attributes) @values = values @types = types @additional_types = additional_types @default_attributes = default_attributes @casted_values = {} @materialized = false end
def key?(name)
def key?(name) (values.key?(name) || types.key?(name) || @attributes.key?(name)) && self[name].initialized? end
def keys
def keys keys = values.keys | types.keys | @attributes.keys keys.keep_if { |name| self[name].initialized? } end