class Dao::Gateway::Base

Attributes

black_list_attributes[R]
source[R]
transformer[R]

Public Class Methods

new(source, transformer) click to toggle source
# File lib/dao/gateway/base.rb, line 6
def initialize(source, transformer)
  @source = source
  @transformer = transformer

  @black_list_attributes = @transformer.export_attributes_black_list
end

Public Instance Methods

add_relations(scope, _relations, _options) click to toggle source
# File lib/dao/gateway/base.rb, line 29
def add_relations(scope, _relations, _options)
  scope
end
chain(_scope, _method_name, _args, &_block) click to toggle source
# File lib/dao/gateway/base.rb, line 25
def chain(_scope, _method_name, _args, &_block)
  fail 'chain is not implemented'
end
delete(_domain_id) click to toggle source
# File lib/dao/gateway/base.rb, line 21
def delete(_domain_id)
  fail 'delete is not implemented'
end
map(object, associations) click to toggle source
# File lib/dao/gateway/base.rb, line 13
def map(object, associations)
  import(object, associations)
end
save!(_domain, _attributes) click to toggle source
# File lib/dao/gateway/base.rb, line 17
def save!(_domain, _attributes)
  fail 'save! is not implemented'
end
serializable_relations(relations) click to toggle source
# File lib/dao/gateway/base.rb, line 41
def serializable_relations(relations)
  convert_array(relations)
end
with_lock(_id, *_args, &_block) click to toggle source
# File lib/dao/gateway/base.rb, line 37
def with_lock(_id, *_args, &_block)
  raise LockNotSupported
end
with_transaction(&_block) click to toggle source
# File lib/dao/gateway/base.rb, line 33
def with_transaction(&_block)
  raise TransactionNotSupported
end

Protected Instance Methods

collection_scope?(relation) click to toggle source
# File lib/dao/gateway/base.rb, line 65
def collection_scope?(relation)
  relation.respond_to? :each
end
convert_array(array) click to toggle source
# File lib/dao/gateway/base.rb, line 77
def convert_array(array)
  array.collect do |value|
    if value.is_a? Hash
      convert_hash(value)
    else
      value
    end
  end
end
convert_hash(hash) click to toggle source
# File lib/dao/gateway/base.rb, line 87
def convert_hash(hash)
  hash.each_with_object({}) do |(key, value), new_hash|
    new_hash[key] =
      if value.is_a? Array
        { include: convert_array(value) }
      elsif value.is_a? Hash
        { include: convert_hash(value) }
      else
        { include: value }
      end
  end
end
export(_base, _record = nil) click to toggle source
# File lib/dao/gateway/base.rb, line 47
def export(_base, _record = nil)
  fail 'export is not implemented'
end
import(relation, associations) click to toggle source
# File lib/dao/gateway/base.rb, line 51
def import(relation, associations)
  @transformer.associations = associations

  unless relation.nil?
    if source_scope?(relation)
      @transformer.one(relation)
    elsif collection_scope?(relation)
      @transformer.many(relation)
    else
      @transformer.other(relation)
    end
  end
end
record(_domain_id) click to toggle source
# File lib/dao/gateway/base.rb, line 73
def record(_domain_id)
  fail 'record is not implemented'
end
source_scope?(relation) click to toggle source
# File lib/dao/gateway/base.rb, line 69
def source_scope?(relation)
  relation.is_a?(source)
end