-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make it rails independent #57
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,14 @@ | |
|
||
module Seedbank | ||
class << self | ||
attr_writer :seeds_root, :nesting, :matcher | ||
attr_writer :application_root | ||
|
||
def application_root | ||
@application_root ||= Pathname.new(Rake.application.original_dir) | ||
end | ||
|
||
def seeds_root | ||
@seeds_root ||= 'db/seeds' | ||
@seeds_root ||= File.join(application_root, 'db', 'seeds') | ||
end | ||
|
||
def nesting | ||
|
@@ -19,8 +23,8 @@ def matcher | |
end | ||
|
||
def self.load_tasks | ||
Dir[File.expand_path("tasks/*.rake", File.dirname(__FILE__))].each { |ext| load ext } | ||
Dir[File.expand_path('../tasks/*.rake', __FILE__)].each { |ext| load ext } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
end | ||
|
||
require 'seedbank/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,7 @@ def define_seed_task(seed_file, *args) | |
runner.evaluate(seed_task, seed_file) if File.exist?(seed_file) | ||
end | ||
|
||
# TODO: Stop being so dependent on Rails.root | ||
# perhaps set Seedbank.application_root instead | ||
relative_file = Pathname.new(seed_file).relative_path_from(Rails.root) | ||
relative_file = Pathname.new(seed_file).relative_path_from(Seedbank.application_root) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [93/80] |
||
|
||
task.add_description "Load the seed data from #{relative_file}" | ||
add_environment_dependency(task) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
module Seedbank | ||
class Railtie < Rails::Railtie | ||
|
||
rake_tasks do | ||
Seedbank.seeds_root = File.expand_path('db/seeds', Rails.root) | ||
Seedbank.load_tasks | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
Rails.backtrace_cleaner.remove_silencers! | ||
|
||
Seedbank.seeds_root = File.expand_path('dummy/db/seeds', __FILE__) | ||
Seedbank.application_root = Pathname.new(File.expand_path('../dummy', __FILE__)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I should prefer single quotes 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely prefer single quotes unless interpolation, it's a good signpost to look closer when there are double quotes. |
||
|
||
class Seedbank::Spec < MiniTest::Spec | ||
def setup | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.