Class: ActiveRecordSchemaScrapper::Attributes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_record_schema_scrapper/attributes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:) ⇒ Attributes

Returns a new instance of Attributes.



32
33
34
35
# File 'lib/active_record_schema_scrapper/attributes.rb', line 32

def initialize(model:)
  @model  = model
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



29
30
31
# File 'lib/active_record_schema_scrapper/attributes.rb', line 29

def errors
  @errors
end

Class Method Details

.register_default(name:, klass:, cast_type: nil, type: nil) ⇒ Object

Parameters:

  • name (String)

    original default value from schema

  • klass (Object)

    the replacement value

  • cast_type (Object#===, Proc#===) (defaults to: nil)

    to be compared to the db schema returned value

  • type (Symbol) (defaults to: nil)

    matches the type from the schema



20
21
22
# File 'lib/active_record_schema_scrapper/attributes.rb', line 20

def register_default(name:, klass:, cast_type: nil, type: nil)
  registered_defaults << [name, klass, cast_type, type]
end

.register_type(name:, klass:, cast_type: nil) ⇒ Object

Parameters:

  • name (Symbol)

    original type from schema

  • klass (Object, Virtus::Attribute)

    a ruby type used to coerce values

  • cast_type (Object#===, Proc#===) (defaults to: nil)

    to be compared to the db schema returned value



8
9
10
# File 'lib/active_record_schema_scrapper/attributes.rb', line 8

def register_type(name:, klass:, cast_type: nil)
  registered_types << [name, klass, cast_type]
end

.registered_defaultsObject



24
25
26
# File 'lib/active_record_schema_scrapper/attributes.rb', line 24

def registered_defaults
  @registered_defaults ||= []
end

.registered_typesObject



12
13
14
# File 'lib/active_record_schema_scrapper/attributes.rb', line 12

def registered_types
  @registered_types ||= []
end

Instance Method Details

#eachObject



39
40
41
# File 'lib/active_record_schema_scrapper/attributes.rb', line 39

def each
  call.each { |attr| yield(attr) }
end

#to_aObject



43
44
45
# File 'lib/active_record_schema_scrapper/attributes.rb', line 43

def to_a
  @to_a ||= map { |v| v }
end