class Para::ModelFieldParsers::Store

Public Instance Methods

applicable?() click to toggle source
# File lib/para/model_field_parsers/store.rb, line 31
def applicable?
  !model.stored_attributes.empty? || model_includes_json_fields?
end
json_field?(field) click to toggle source
# File lib/para/model_field_parsers/store.rb, line 41
def json_field?(field)
  field.type.to_s.in?(%w(json jsonb))
end
model_includes_json_fields?() click to toggle source
# File lib/para/model_field_parsers/store.rb, line 35
def model_includes_json_fields?
  fields_hash.any? do |_, field|
    json_field?(field)
  end
end
parse!() click to toggle source
# File lib/para/model_field_parsers/store.rb, line 6
def parse!
  process_stored_attributes
  process_remaining_json_fields
end
process_remaining_json_fields() click to toggle source

Duplicate fields to avoid updating the hash while iterating through it then remove remaining json fields from the hash

# File lib/para/model_field_parsers/store.rb, line 25
def process_remaining_json_fields
  fields_hash.dup.each do |key, field|
    fields_hash.delete(key) if json_field?(field)
  end
end
process_stored_attributes() click to toggle source
# File lib/para/model_field_parsers/store.rb, line 11
def process_stored_attributes
  model.stored_attributes.each do |store_key, field_names|
    fields_hash.delete(store_key)

    field_names.each do |field_name|
      fields_hash[field_name] = AttributeField::Base.new(
        model, name: field_name, type: :string, searchable: false
      )
    end
  end
end