Skip to content

Commit cb2a3a1

Browse files
authored
Merge pull request #55 from excid3/install-task
Add install task
2 parents db8fc9a + c2d58be commit cb2a3a1

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ end
196196

197197
1. Add the `kredis` gem to your Gemfile: `gem 'kredis'`
198198
2. Run `./bin/bundle install`
199-
3. Add a default configuration under `config/redis/shared.yml`
199+
3. Run `./bin/rails kredis:install` to add a default configuration under `config/redis/shared.yml`
200200

201201
A default configuration can look like this for `config/redis/shared.yml`:
202202

lib/install/install.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
yaml_path = Rails.root.join("config/redis/shared.yml")
2+
unless yaml_path.exist?
3+
say "Adding `config/redis/shared.yml`"
4+
empty_directory yaml_path.parent.to_s
5+
copy_file "#{__dir__}/shared.yml", yaml_path
6+
end

lib/install/shared.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
production: &production
2+
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
3+
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
4+
timeout: 1
5+
6+
development: &development
7+
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
8+
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
9+
timeout: 1
10+
11+
test:
12+
<<: *development

lib/kredis/railtie.rb

+5
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ class Kredis::Railtie < ::Rails::Railtie
3030
include Kredis::Attributes
3131
end
3232
end
33+
34+
rake_tasks do
35+
path = File.expand_path("..", __dir__)
36+
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
37+
end
3338
end

lib/tasks/kredis/install.rake

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace :kredis do
2+
desc "Install kredis"
3+
task :install do
4+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}"
5+
end
6+
end

0 commit comments

Comments
 (0)