diff options
author | Noah Silvera <noah@super.gd> | 2021-06-21 15:45:53 -0700 |
---|---|---|
committer | Nicholas Van Doorn <vandoorn.nick@gmail.com> | 2021-07-26 15:39:50 -0700 |
commit | a06d8d50cd99feb45b560c27d1d2581e703aa824 (patch) | |
tree | d88b4efd1ea60bf634f61a9718941b18f6b7baa2 | |
parent | b7af04133f796b14bef0781e918d7eb7a46f6c0e (diff) |
Add install generator
Prior to this commit, users were required to manually configure this
extension after installing the gem. We add an install generator so users
can run a single command to handle this.
We include this command in the sandbox script so the sandbox is
ready to use this extension by default.
Co-authored-by: Noah Silvera <noah@super.gd>
-rw-r--r-- | README.md | 12 | ||||
-rwxr-xr-x | bin/sandbox | 1 | ||||
-rw-r--r-- | lib/generators/super_good/solidus_taxjar/install_generator.rb | 18 |
3 files changed, 23 insertions, 8 deletions
@@ -16,15 +16,11 @@ This is not a fork of [spree_taxjar](https://github.com/vinsol-spree-contrib/spr $ bundle -2. Next, configure Solidus to use this gem: +2. Next, configure Solidus to use this gem by running the install generator: - ```ruby - # Put this in config/initializers/solidus.rb - - Spree.config do |config| - config.tax_calculator_class = SuperGood::SolidusTaxjar::TaxCalculator - end - ``` + ```sh + bundle exec rails generate super_good:solidus_taxjar:install + ``` 3. Also, configure your error handling: diff --git a/bin/sandbox b/bin/sandbox index 90b8b81..53731cf 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -75,6 +75,7 @@ unbundled bundle exec rails generate spree:install \ $@ unbundled bundle exec rails generate solidus:auth:install +unbundled bundle exec rails generate super_good:solidus_taxjar:install echo echo "🚀 Sandbox app successfully created for $extension_name!" diff --git a/lib/generators/super_good/solidus_taxjar/install_generator.rb b/lib/generators/super_good/solidus_taxjar/install_generator.rb new file mode 100644 index 0000000..73974ba --- /dev/null +++ b/lib/generators/super_good/solidus_taxjar/install_generator.rb @@ -0,0 +1,18 @@ +module SuperGood + module SolidusTaxjar + module Generators + class InstallGenerator < Rails::Generators::Base + def create_initializer_file + solidus_initializer_path = "config/initializers/solidus.rb" + + create_file(solidus_initializer_path) unless File.exists?(solidus_initializer_path) + append_to_file(solidus_initializer_path, <<~INIT) + Spree.config do |config| + config.tax_calculator_class = SuperGood::SolidusTaxjar::TaxCalculator + end + INIT + end + end + end + end +end |