Class: Bank::CollectionConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/bank/collection_config.rb

Constant Summary collapse

IDENTITY =
->(i) { i }

Instance Method Summary collapse

Instance Method Details

#columnsObject



38
39
40
# File 'lib/bank/collection_config.rb', line 38

def columns
  @_columns ||= Bank.db.schema(db)
end

#columns_of_type(type) ⇒ Object



42
43
44
# File 'lib/bank/collection_config.rb', line 42

def columns_of_type(type)
  columns.select { |col, opts| opts[:type] == type }
end

#db(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/bank/collection_config.rb', line 24

def db(&block)
  if block_given?
    @_db_block = block
    @_db = nil
  else
    value = @_db_block.call
    @_db ||= value.is_a?(Symbol) ? Bank[value] : value
  end
end

#model(&block) ⇒ Object



9
10
11
# File 'lib/bank/collection_config.rb', line 9

def model(&block)
  block_given? ? self._model_block = block : @_model ||= _model_block.call
end

#packer(blk) ⇒ Object



13
# File 'lib/bank/collection_config.rb', line 13

def packer(blk)   packers << blk   end

#packersObject



16
17
18
# File 'lib/bank/collection_config.rb', line 16

def packers
  @_packers ||= Bank.config.default_packers
end

#primary_key(value = nil) ⇒ Object



34
35
36
# File 'lib/bank/collection_config.rb', line 34

def primary_key(value = nil)
  value ?  @_primary_key = value : @_primary_key ||= :id
end

#unpacker(blk) ⇒ Object



14
# File 'lib/bank/collection_config.rb', line 14

def unpacker(blk) unpackers << blk end

#unpackersObject



20
21
22
# File 'lib/bank/collection_config.rb', line 20

def unpackers
  @_unpackers ||= Bank.config.default_unpackers
end