Module: AssociateJsonb::ArelExtensions::Table

Defined in:
lib/associate_jsonb/arel_extensions/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#store_trackerObject (readonly)

Returns the value of attribute store_tracker.



7
8
9
# File 'lib/associate_jsonb/arel_extensions/table.rb', line 7

def store_tracker
  @store_tracker
end

Instance Method Details

#[](name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/associate_jsonb/arel_extensions/table.rb', line 23

def [](name)
  return super unless store_col = store_tracker&.get(name)

  attr = ::Arel::Nodes::Jsonb::DashDoubleArrow.
    new(self, self[store_col[:store]], store_col[:key])

  if cast_as = (store_col[:cast] && store_col[:cast][:sql_type])
    attr = ::Arel::Nodes::NamedFunction.new(
      "CAST",
      [ attr.as(cast_as) ]
    )
  end

  Arel::Nodes::Jsonb::Attribute.new(self, name, attr)
end

#aliasObject



14
15
16
# File 'lib/associate_jsonb/arel_extensions/table.rb', line 14

def alias(...)
  super(...).with_store_tracker(store_tracker)
end

#initialize(*args, store_tracker: nil, **opts) ⇒ Object



9
10
11
12
# File 'lib/associate_jsonb/arel_extensions/table.rb', line 9

def initialize(*args, store_tracker: nil, **opts)
  @store_tracker = store_tracker
  super(*args, **opts)
end

#with_store_tracker(tracker) ⇒ Object



18
19
20
21
# File 'lib/associate_jsonb/arel_extensions/table.rb', line 18

def with_store_tracker(tracker)
  @store_tracker = tracker
  self
end