Skip to content

Commit

Permalink
Fix issues after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
imdrasil committed Jul 5, 2018
1 parent cf07f51 commit f67189b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
10 changes: 7 additions & 3 deletions spec/config_spec.cr
@@ -1,7 +1,11 @@
require "./spec_helper"

private def config
Jennifer::Config.config
end

describe Jennifer::Config do
config = Jennifer::Config.config
described_class = Jennifer::Config

describe "::read" do
it "reads data from yaml file" do
Expand Down Expand Up @@ -29,11 +33,11 @@ describe Jennifer::Config do

it "expects adapter and database at very least" do
expect_raises(Jennifer::InvalidConfig, /No database configured/) do
config.configure { |c| c.db = "" }
described_class.configure { |c| c.db = "" }
end

expect_raises(Jennifer::InvalidConfig, /No adapter configured/) do
config.configure do |c|
described_class.configure do |c|
c.db = "somedb"
c.adapter = ""
end
Expand Down
37 changes: 23 additions & 14 deletions src/jennifer/config.cr
Expand Up @@ -132,7 +132,6 @@ module Jennifer
@local_time_zone
end


delegate_getter(:local_time_zone)

def self.migration_failure_handler_method=(value)
Expand All @@ -156,25 +155,29 @@ module Jennifer
raise Jennifer::InvalidConfig.new("No database configured") if db.empty?
end

def self.from_uri(db_uri : String)
begin
from_uri(URI.parse(db_uri))
rescue e
config.logger.error("Error parsing database uri #{db_uri}")
end
def self.from_uri(uri)
config.from_uri(uri)
end

def self.read(*args, **opts)
config.read(*args, **opts)
end

def self.from_uri(uri : URI)
config.set_from_uri(uri)
def self.read(*args, **opts)
config.read(*args, **opts) { |document| yield document }
end

def self.read(path : String, env : String | Symbol = :development)
def read(path : String)
source = yield YAML.parse(File.read(path))
from_yaml(source)
end

def read(path : String, env : String | Symbol = :development)
_env = env.to_s
source = YAML.parse(File.read(path))[_env]
config.set_from_yaml(source)
read(path) { |document| document[_env] }
end

def set_from_yaml(source)
def from_yaml(source)
{% for field in STRING_FIELDS %}
@{{field.id}} = source["{{field.id}}"].as_s if source["{{field.id}}"]?
{% end %}
Expand All @@ -193,7 +196,13 @@ module Jennifer
self
end

def set_from_uri(uri : URI)
def from_uri(uri : String)
from_uri(URI.parse(uri))
rescue e
logger.error("Error parsing database uri #{uri}")
end

def from_uri(uri : URI)
@adapter = uri.scheme.to_s if uri.scheme
@host = uri.host.to_s if uri.host
@port = uri.port.not_nil! if uri.port
Expand Down
4 changes: 4 additions & 0 deletions src/jennifer/migration/base.cr
Expand Up @@ -53,6 +53,10 @@ module Jennifer
def after_down_failure
end

def self.version
raise AbstractMethod.new(self, :version)
end

def self.versions
migrations.map(&.version)
end
Expand Down

0 comments on commit f67189b

Please sign in to comment.