summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2020-09-24 13:52:25 +0200
committerAlessandro Desantis <desa.alessandro@gmail.com>2020-09-24 13:53:28 +0200
commit9ab99ab24fc36805eac3c1fefef85aafe90cf7b8 (patch)
tree9ca61e02fc2fa304d1491307400298c4b4e1ac6b /lib
parent11b1a59321f238a3a7fc8802e8f7316cee7d1e80 (diff)
Copy default configuration to an initializer during installation
Diffstat (limited to 'lib')
-rw-r--r--lib/generators/solidus_subscriptions/install/install_generator.rb6
-rw-r--r--lib/generators/solidus_subscriptions/install/templates/initializer.rb78
-rw-r--r--lib/solidus_subscriptions/config.rb38
3 files changed, 84 insertions, 38 deletions
diff --git a/lib/generators/solidus_subscriptions/install/install_generator.rb b/lib/generators/solidus_subscriptions/install/install_generator.rb
index 42cc4f8..bd7a6a4 100644
--- a/lib/generators/solidus_subscriptions/install/install_generator.rb
+++ b/lib/generators/solidus_subscriptions/install/install_generator.rb
@@ -3,8 +3,14 @@
module SolidusSubscriptions
module Generators
class InstallGenerator < Rails::Generators::Base
+ source_root File.expand_path('templates', __dir__)
+
class_option :auto_run_migrations, type: :boolean, default: false
+ def copy_initializer
+ template 'initializer.rb', 'config/initializers/solidus_subscriptions.rb'
+ end
+
def add_javascripts
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n"
end
diff --git a/lib/generators/solidus_subscriptions/install/templates/initializer.rb b/lib/generators/solidus_subscriptions/install/templates/initializer.rb
new file mode 100644
index 0000000..3de5182
--- /dev/null
+++ b/lib/generators/solidus_subscriptions/install/templates/initializer.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+SolidusSubscriptions::Config.tap do |config|
+ # These handlers are pluggable, however it is highly encouraged that
+ # you subclass from the the dispatcher you are replacing, and call
+ # `super` from within the #dispatch method (if you override it).
+
+ # This handler is called when a subscription order is successfully placed.
+ # config.success_dispatcher_class = 'SolidusSubscriptions::SuccessDispatcher'
+
+ # This handler is called when a group of installments fails to be processed.
+ # config.failure_dispatcher_class = 'SolidusSubscriptions::FailureDispatcher'
+
+ # This handler is called when a payment fails on a subscription order.
+ # config.payment_failed_dispatcher_class = 'SolidusSubscriptions::PaymentFailedDispatcher'
+
+ # This handler is called when there isn't enough stock to fulfill an installment.
+ # config.out_of_stock_dispatcher = 'SolidusSubscriptions::OutOfStockDispatcher'
+
+ # Maximum number of times a user can skip their subscription before it
+ # must be processed.
+ # config.maximum_successive_skips = 1
+
+ # Maximum number of times a user can skip their subscription. Once this limit
+ # is reached, no more skips are permitted.
+ # config.maximum_total_skips = nil
+
+ # Minimum days between the current date and the next installment for the
+ # installment not to be processed after subscription cancellation.
+ # config.minimum_cancellation_notice = 1.day
+
+ # Time between an installment failing to be processed and the system
+ # retrying to fulfill it.
+ # config.reprocessing_interval = 1.day
+
+ # Which queue is responsible for processing subscription background jobs.
+ # config.processing_queue = :default
+
+ # SolidusSubscriptions::LineItem attributes which are allowed to
+ # be updated from user data
+ #
+ # This is useful in the case where certain fields should not be allowed to
+ # be modified by the user. This locks these attributes from being passed
+ # to the orders controller (or the API controller).
+ #
+ # For example, if a store does not want to allow users to configure the end
+ # date of a subscription, set this:
+ #
+ # ```
+ # SolidusSubscriptions::Config.subscription_line_item_attributes = [
+ # :quantity,
+ # :subscribable_id,
+ # :interval_length,
+ # :interval_units,
+ # ]
+ # ```
+ #
+ # You can also add additional attributes that you want to track in the
+ # subscription line items.
+ # config.subscription_line_item_attributes = [
+ # :quantity,
+ # :subscribable_id,
+ # :interval_length,
+ # :interval_units,
+ # :end_date,
+ # ]
+
+ # SolidusSubscriptions::Subscription attributes which are allowed to
+ # be modified by the user.
+ # config.subscription_attributes = [
+ # :interval_length,
+ # :interval_units,
+ # :end_date,
+ # :actionable_date,
+ # shipping_address_attributes: Spree::PermittedAttributes.address_attributes,
+ # billing_address_attributes: Spree::PermittedAttributes.address_attributes,
+ # ]
+end
diff --git a/lib/solidus_subscriptions/config.rb b/lib/solidus_subscriptions/config.rb
index 549c1ce..20ebd20 100644
--- a/lib/solidus_subscriptions/config.rb
+++ b/lib/solidus_subscriptions/config.rb
@@ -1,73 +1,37 @@
module SolidusSubscriptions
module Config
class << self
- # Processing Event handlers
- # These handlers are pluggable, however it is highly encouraged that you
- # subclass from the the dispatcher you are replacing, and call super
- # from within the #dispatch method (if you override it)
- #
- # This handler is called when a susbcription order is successfully placed.
attr_writer :success_dispatcher_class
def success_dispatcher_class
@success_dispatcher_class ||= ::SolidusSubscriptions::SuccessDispatcher
end
- # This handler is called when an order cant be placed for a group of
- # installments
attr_writer :failure_dispatcher_class
def failure_dispatcher_class
@failure_dispatcher_class ||= ::SolidusSubscriptions::FailureDispatcher
end
- # This handler is called when a payment fails on a subscription order
attr_writer :payment_failed_dispatcher_class
def payment_failed_dispatcher_class
@payment_failed_dispatcher_class ||= ::SolidusSubscriptions::PaymentFailedDispatcher
end
- # This handler is called when installemnts cannot be fulfilled due to lack
- # of stock
attr_writer :out_of_stock_dispatcher
def out_of_stock_dispatcher_class
@out_of_stock_dispatcher_class ||= ::SolidusSubscriptions::OutOfStockDispatcher
end
end
- # Maximum number of times a user can skip their subscription before it
- # must be processed
mattr_accessor(:maximum_successive_skips) { 1 }
- # Limit on the number of times a user can skip thier subscription. Once
- # this limit is reached, no skips are permitted
mattr_accessor(:maximum_total_skips) { nil }
- # Time between an installment failing to be processed and the system
- # retrying to fulfil it
mattr_accessor(:reprocessing_interval) { 1.day }
mattr_accessor(:minimum_cancellation_notice) { 1.day }
- # Which queue is responsible for processing subscriptions
mattr_accessor(:processing_queue) { :default }
- # SolidusSubscriptions::LineItem attributes which are allowed to
- # be updated from user data
- #
- # This is useful in the case where certain fields should not be allowed to
- # be modified by the user. This locks these attributes from being passed
- # in to the orders controller (or the api controller).
- # Ie. if a store does not want to allow users to configure the end date of
- # a subscription. Add this to an initializer:
- # ```
- # SolidusSubscriptions::Config.subscription_line_item_attributes = [
- # :quantity,
- # :subscribable_id,
- # :interval_length,
- # :interval_units,
- # ]
- # ```
- # This configuration also easily allows the gem to be customized to track
- # more information on the subscriptions line items.
mattr_accessor(:subscription_line_item_attributes) do
[
:quantity,
@@ -78,8 +42,6 @@ module SolidusSubscriptions
]
end
- # SolidusSubscriptions::Subscription attributes which are allowed to
- # be updated from user data
mattr_accessor(:subscription_attributes) do
[
:interval_length,