class Ars::Familiar::Base

Public Instance Methods

attributes_to_define() click to toggle source
# File lib/ars/familiar/base.rb, line 23
def attributes_to_define
  @attributes_to_define || attributes_to_define!
end
extract_options(**opts) click to toggle source
# File lib/ars/familiar/base.rb, line 31
def extract_options(**opts)
  class_map = map_classes(opts)

  only = opts.fetch(:only, :pass).entries.each_with_object(class_map) {|val, hash|  hash.store(*val) }.keys
  class_map

  filter = proc do |relation|
    name = relation[:name]

    only == :pass || only.include?(name)
  end

  [filter, class_map]
end
id() click to toggle source
# File lib/ars/familiar/base.rb, line 19
def id
  @id || id!
end
map_classes(**opts) click to toggle source
# File lib/ars/familiar/base.rb, line 46
def map_classes(**opts)
  class_base  = opts.fetch(:class_base, nil)
  class_name  = opts.fetch(:class_name, false)
  class_names = opts.fetch(:class_names, {})

  Hash.new {|hash, key| hash[key] = [class_base, key].constantize }.
    tap {|this| class_name && this.default = class_name}.
    merge(class_names)
end
relationships_to_define(**opts) click to toggle source
# File lib/ars/familiar/base.rb, line 27
def relationships_to_define(**opts)
  @relationships_to_define || relationships_to_define!(**opts)
end
scribe(dump) click to toggle source
# File lib/ars/familiar/base.rb, line 5
def scribe(dump)
  if dump
    %i{ attributes_to_define relationships_to_define primary_key id }.each do |attr|
      const_set "@#{attr}", dump[attr]
    end
  end
  {
    attributes_to_define: @attributes_to_define,
    relationships_to_define: @relationships_to_define,
    primary_key: @primary_key,
    id: @id
  }
end