Class: LcpRuby::ModelFactory::ArrayTypeApplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/model_factory/array_type_applicator.rb

Overview

Registers ActiveRecord attribute types for array fields. On PostgreSQL, native array columns work out of the box — only the default is set. On SQLite/MySQL, a custom ArrayType handles JSON serialization transparently.

Instance Method Summary collapse

Constructor Details

#initialize(model_class, model_definition) ⇒ ArrayTypeApplicator

Returns a new instance of ArrayTypeApplicator.



7
8
9
10
# File 'lib/lcp_ruby/model_factory/array_type_applicator.rb', line 7

def initialize(model_class, model_definition)
  @model_class = model_class
  @model_definition = model_definition
end

Instance Method Details

#apply!Object



12
13
14
15
16
17
18
19
20
# File 'lib/lcp_ruby/model_factory/array_type_applicator.rb', line 12

def apply!
  @model_definition.fields.select(&:array?).each do |field|
    if LcpRuby.postgresql?
      apply_pg_array(field)
    else
      apply_json_array(field)
    end
  end
end