require 'legion/data/version' require 'sequel' require 'legion/data/connection' require 'legion/data/migration' require 'legion/data/model' module Legion module Data def build(options = {}) @connected = false options.merge!(default_options) { |_key, v1, _v2| v1 } @connection = connect(options[:connection]) if options[:connection][:auto_connect] return unless options[:connection][:auto_connect] migrate(@connection, options[:migration]) model(options[:model]) if options[:model][:auto_load] end def connect(_options = {}) Legion::Data::Connection.new end def migrate(connection, options = {}) return false if options.key?(:auto_migrate) && options[:auto_migrate] Legion::Data::Migration.new(connection.database.connection) end def model(_options = {}) Legion::Data::Models.new end def default_options { migration: { auto_migrate: true }, model: { auto_load: true }, connection: { auto_connect: true } } end def merge_options(options, default = default_options) options.merge!(default) { |_key, v1, _v2| v1 } end end end