Class: Bmg::Database::Sequel

Inherits:
Bmg::Database show all
Defined in:
lib/bmg/database/sequel.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
}

Instance Method Summary collapse

Methods inherited from Bmg::Database

data_folder, sequel, #to_data_folder, #to_xlsx, xlsx

Constructor Details

#initialize(sequel_db, options = {}) ⇒ Sequel

Returns a new instance of Sequel.



8
9
10
11
# File 'lib/bmg/database/sequel.rb', line 8

def initialize(sequel_db, options = {})
  @sequel_db = sequel_db
  @sequel_db = ::Sequel.connect(@sequel_db) unless @sequel_db.is_a?(::Sequel::Database)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &bl) ⇒ Object



13
14
15
16
17
# File 'lib/bmg/database/sequel.rb', line 13

def method_missing(name, *args, &bl)
  return super(name, *args, &bl) unless args.empty? && bl.nil?
  raise NotSuchRelationError(name.to_s) unless @sequel_db.table_exists?(name)
  rel_for(name)
end

Instance Method Details

#each_relation_pairObject



19
20
21
22
23
24
25
# File 'lib/bmg/database/sequel.rb', line 19

def each_relation_pair
  return to_enum(:each_relation_pair) unless block_given?

  @sequel_db.tables.each do |table|
    yield(table, rel_for(table))
  end
end