diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bce8d14..26a23b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ * TODO +### 0.46.0 + +* Autoload knapsack_pro rake tasks with Rails Railties + + https://github.com/KnapsackPro/knapsack_pro-ruby/pull/47 + +https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.45.0...v0.46.0 + ### 0.45.0 * Add before and after queue hooks diff --git a/README.md b/README.md index 3685e68a..935074a5 100644 --- a/README.md +++ b/README.md @@ -159,12 +159,16 @@ end And then execute: - $ bundle install - +``` +$ bundle install +``` -Add this line at the bottom of `Rakefile` if your project has one: +If you are not using Rails then add this line at the bottom of `Rakefile`: ```ruby +# Add this only if you are not using Rails. +# If you use Rails then knapsack_pro rake tasks are already loaded +# so there is no need to explicitly load them. KnapsackPro.load_tasks if defined?(KnapsackPro) ``` diff --git a/lib/knapsack_pro.rb b/lib/knapsack_pro.rb index f4deea29..518d9b7f 100644 --- a/lib/knapsack_pro.rb +++ b/lib/knapsack_pro.rb @@ -61,6 +61,8 @@ require_relative 'knapsack_pro/crypto/decryptor' require_relative 'knapsack_pro/crypto/digestor' +require 'knapsack_pro/railtie' if defined?(Rails::Railtie) + module KnapsackPro class << self def root diff --git a/lib/knapsack_pro/railtie.rb b/lib/knapsack_pro/railtie.rb new file mode 100644 index 00000000..90ca4879 --- /dev/null +++ b/lib/knapsack_pro/railtie.rb @@ -0,0 +1,10 @@ +require 'rails' +require 'knapsack_pro' + +module KnapsackPro + class Railtie < Rails::Railtie + rake_tasks do + KnapsackPro.load_tasks + end + end +end