Class: ActiveRecordSchemaScrapper::Attributes
Defined Under Namespace
Modules: DeprecatedRegisterDefaultKeywords
Constant Summary
collapse
- DEFAULT_REGISTERED_TYPES =
{ type: :integer, replacement_type: Integer },
{ type: :float, replacement_type: Float },
{ type: :decimal, replacement_type: BigDecimal },
{ type: Proc.new { |t| [:timestamp, :time].include?(t) }, replacement_type: Time },
{ type: :datetime, replacement_type: DateTime },
{ type: :date, replacement_type: Date },
{ type: Proc.new { |t| %i{text string binary}.include?(t) }, replacement_type: String },
{ type: :boolean, replacement_type: Axiom::Types::Boolean },
{ type: :hstore, replacement_type: Hash },
].freeze
- DEFAULT_REGISTERED_DEFAULTS =
[
{ default: Proc.new { |d| d == 't' }, replacement_default: true, type: :boolean },
{ default: Proc.new { |d| d == 'f' }, replacement_default: false, type: :boolean },
{ default: Proc.new { |d| d == '1' }, replacement_default: true, type: :boolean },
{ default: Proc.new { |d| d == '0' }, replacement_default: false, type: :boolean }
].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
register_default
Constructor Details
#initialize(model:) ⇒ Attributes
Returns a new instance of Attributes.
84
85
86
87
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 84
def initialize(model:)
@model = model
@errors = []
end
|
Class Method Details
.register_default(default:, replacement_default:, cast_type: :not_given, type: :not_given) ⇒ Object
68
69
70
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 68
def register_default(default:, replacement_default:, cast_type: :not_given, type: :not_given)
registered_defaults << { default: default, replacement_default: replacement_default, cast_type: cast_type, type: type }
end
|
.register_type(name:, klass:, cast_type: :not_given) ⇒ Object
26
27
28
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 26
def register_type(name:, klass:, cast_type: :not_given)
registered_types << { type: name, replacement_type: klass, cast_type: cast_type }
end
|
.registered_defaults ⇒ Object
72
73
74
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 72
def registered_defaults
@registered_defaults ||= DEFAULT_REGISTERED_DEFAULTS.dup
end
|
.registered_types ⇒ Object
30
31
32
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 30
def registered_types
@registered_types ||= DEFAULT_REGISTERED_TYPES.dup
end
|
.reset_registered_defaults ⇒ Object
76
77
78
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 76
def reset_registered_defaults
@registered_defaults = DEFAULT_REGISTERED_DEFAULTS.dup
end
|
.reset_registered_types ⇒ Object
34
35
36
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 34
def reset_registered_types
@registered_types = DEFAULT_REGISTERED_TYPES.dup
end
|
Instance Method Details
#each ⇒ Object
91
92
93
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 91
def each
call.each { |attr| yield(attr) }
end
|
#errors ⇒ Object
99
100
101
102
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 99
def errors
to_a
@errors
end
|
#to_a ⇒ Object
95
96
97
|
# File 'lib/active_record_schema_scrapper/attributes.rb', line 95
def to_a
@to_a ||= map { |v| v }
end
|