Class: Sequel::ReadyMaker
- Inherits:
-
Object
- Object
- Sequel::ReadyMaker
- Defined in:
- lib/sequel/extensions/make_readyable.rb
Defined Under Namespace
Classes: FileSourcerer
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #create_view(source, table, schema) ⇒ Object
- #get_source(db, schema) ⇒ Object
-
#initialize(db, opts) ⇒ ReadyMaker
constructor
A new instance of ReadyMaker.
- #run ⇒ Object
Constructor Details
#initialize(db, opts) ⇒ ReadyMaker
Returns a new instance of ReadyMaker.
42 43 44 45 |
# File 'lib/sequel/extensions/make_readyable.rb', line 42 def initialize(db, opts) @db = db @opts = opts end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
40 41 42 |
# File 'lib/sequel/extensions/make_readyable.rb', line 40 def db @db end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
40 41 42 |
# File 'lib/sequel/extensions/make_readyable.rb', line 40 def opts @opts end |
Instance Method Details
#create_view(source, table, schema) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/sequel/extensions/make_readyable.rb', line 66 def create_view(source, table, schema) if schema.to_s =~ %r{/} source.create_view(table, temp: true) else source.create_view(table, db[Sequel.qualify(schema, table)], temp: true) end end |
#get_source(db, schema) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/sequel/extensions/make_readyable.rb', line 74 def get_source(db, schema) if schema.to_s =~ %r{/} FileSourcerer.new(db, Pathname.new(schema)) else db end end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sequel/extensions/make_readyable.rb', line 47 def run if opts[:use_schema] db.extension :usable db.use(opts[:use_schema]) end only_tables = Array(opts[:only]) created_views = (Array(opts[:except]) || []) (opts[:search_path] || []).each do |schema| schema = schema.is_a?(Pathname) ? schema : schema.to_sym source = get_source(db, schema) tables = source.tables(schema: schema) - created_views tables &= only_tables unless only_tables.empty? tables.each do |table| create_view(source, table, schema) created_views << table end end end |