effective_resources 2.17.4 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/app/models/concerns/acts_as_purchasable_wizard.rb +29 -0
 - data/app/models/concerns/acts_as_statused.rb +5 -1
 - data/app/models/concerns/acts_as_tokened.rb +1 -1
 - data/app/models/concerns/acts_as_wizard.rb +5 -1
 - data/lib/effective_resources/effective_gem.rb +1 -1
 - data/lib/effective_resources/version.rb +1 -1
 - data/lib/effective_resources.rb +7 -2
 - metadata +23 -9
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 39ecd0ecd2a6e70ee849e768b239f37f5922b5bf4625f09cfd1fc5856008361f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b35eb86cf1db76ac404f64655b40aadc483ea6d0792d8d8e832f9d5d03eb2ea2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 947eeacd7e1569c4d942423e55c77abeec47d9a66901e7fed5a326a09136b7b966c8f50e05b58f447c517240e88440f31258a8d96418be6e5f180de90a80767b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4db9d6528ff9c7aa51421ed3c9e4745b0c7ee764144e27d6abda886c014493a0135c3617b6420e82fd3df7abe4b162488b111f58decf3d1cd214d5fb78bf0720
         
     | 
| 
         @@ -77,6 +77,9 @@ module ActsAsPurchasableWizard 
     | 
|
| 
       77 
77 
     | 
    
         
             
                # This will update all order items to match the prices from their purchasable
         
     | 
| 
       78 
78 
     | 
    
         
             
                order.try(:update_purchasable_attributes)
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
                # Handle effective_memberships coupon fees price reduction
         
     | 
| 
      
 81 
     | 
    
         
            +
                reduce_order_item_coupon_fee_price(order)
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       80 
83 
     | 
    
         
             
                # Hook to extend for coupon fees
         
     | 
| 
       81 
84 
     | 
    
         
             
                order = before_submit_order_save(order)
         
     | 
| 
       82 
85 
     | 
    
         
             
                raise('before_submit_order_save must return an Effective::Order') unless order.kind_of?(Effective::Order)
         
     | 
| 
         @@ -91,6 +94,32 @@ module ActsAsPurchasableWizard 
     | 
|
| 
       91 
94 
     | 
    
         
             
                order
         
     | 
| 
       92 
95 
     | 
    
         
             
              end
         
     | 
| 
       93 
96 
     | 
    
         | 
| 
      
 97 
     | 
    
         
            +
              # This is used by effective_memberships and effective_events
         
     | 
| 
      
 98 
     | 
    
         
            +
              # Which both add coupon_fees to their submit_fees
         
     | 
| 
      
 99 
     | 
    
         
            +
              def reduce_order_item_coupon_fee_price(order)
         
     | 
| 
      
 100 
     | 
    
         
            +
                # This only applies to orders with coupon fees
         
     | 
| 
      
 101 
     | 
    
         
            +
                order_items = order.order_items.select { |oi| oi.purchasable.try(:coupon_fee?) }
         
     | 
| 
      
 102 
     | 
    
         
            +
                return order unless order_items.present?
         
     | 
| 
      
 103 
     | 
    
         
            +
                raise('multiple coupon fees not supported') if order_items.length > 1
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                # Get the coupon fee
         
     | 
| 
      
 106 
     | 
    
         
            +
                order_item = order_items.first
         
     | 
| 
      
 107 
     | 
    
         
            +
                coupon_fee = order_item.purchasable
         
     | 
| 
      
 108 
     | 
    
         
            +
                raise('expected order item for coupon fee to be a negative price') unless coupon_fee.price.to_i < 0
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                # Calculate price
         
     | 
| 
      
 111 
     | 
    
         
            +
                subtotal = order.order_items.reject { |oi| oi.purchasable.try(:coupon_fee?) }.sum(&:subtotal)
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                price = 0 if subtotal <= 0
         
     | 
| 
      
 114 
     | 
    
         
            +
                price ||= [coupon_fee.price, (0 - subtotal)].max
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                # Assign the price to this order item. Underlying fee price stays the same.
         
     | 
| 
      
 117 
     | 
    
         
            +
                order_item.assign_attributes(price: price)
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                # Return the order
         
     | 
| 
      
 120 
     | 
    
         
            +
                order
         
     | 
| 
      
 121 
     | 
    
         
            +
              end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
       94 
123 
     | 
    
         
             
              # Should be indempotent.
         
     | 
| 
       95 
124 
     | 
    
         
             
              def build_submit_fees_and_order
         
     | 
| 
       96 
125 
     | 
    
         
             
                return false if was_submitted?
         
     | 
| 
         @@ -34,7 +34,11 @@ module ActsAsStatused 
     | 
|
| 
       34 
34 
     | 
    
         
             
                  status_steps           :text, permitted: false
         
     | 
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                 
     | 
| 
      
 37 
     | 
    
         
            +
                if EffectiveResources.serialize_with_coder?
         
     | 
| 
      
 38 
     | 
    
         
            +
                  serialize :status_steps, type: Hash, coder: YAML
         
     | 
| 
      
 39 
     | 
    
         
            +
                else
         
     | 
| 
      
 40 
     | 
    
         
            +
                  serialize :status_steps, Hash
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
       38 
42 
     | 
    
         | 
| 
       39 
43 
     | 
    
         
             
                const_set(:STATUSES, acts_as_statused_options[:statuses])
         
     | 
| 
       40 
44 
     | 
    
         | 
| 
         @@ -55,7 +55,11 @@ module ActsAsWizard 
     | 
|
| 
       55 
55 
     | 
    
         
             
                  wizard_steps           :text, permitted: false
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                 
     | 
| 
      
 58 
     | 
    
         
            +
                if EffectiveResources.serialize_with_coder?
         
     | 
| 
      
 59 
     | 
    
         
            +
                  serialize :wizard_steps, type: Hash, coder: YAML
         
     | 
| 
      
 60 
     | 
    
         
            +
                else
         
     | 
| 
      
 61 
     | 
    
         
            +
                  serialize :wizard_steps, Hash
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
       59 
63 
     | 
    
         | 
| 
       60 
64 
     | 
    
         
             
                before_save(if: -> { current_step.present? }) do
         
     | 
| 
       61 
65 
     | 
    
         
             
                  wizard_steps[current_step.to_sym] ||= Time.zone.now
         
     | 
| 
         @@ -28,7 +28,7 @@ module EffectiveGem 
     | 
|
| 
       28 
28 
     | 
    
         
             
              module ClassMethods
         
     | 
| 
       29 
29 
     | 
    
         
             
                def config(namespace = nil)
         
     | 
| 
       30 
30 
     | 
    
         
             
                  namespace ||= Tenant.current if defined?(Tenant)
         
     | 
| 
       31 
     | 
    
         
            -
                  @config 
     | 
| 
      
 31 
     | 
    
         
            +
                  (@config[namespace] if namespace) || @config[:effective]
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                def setup(namespace = nil, &block)
         
     | 
    
        data/lib/effective_resources.rb
    CHANGED
    
    | 
         @@ -16,6 +16,11 @@ module EffectiveResources 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              include EffectiveGem
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
      
 19 
     | 
    
         
            +
              # We use the newer syntax for serialize calls in rails 7+
         
     | 
| 
      
 20 
     | 
    
         
            +
              def self.serialize_with_coder?
         
     | 
| 
      
 21 
     | 
    
         
            +
                Gem::Version.new(Gem.loaded_specs['rails'].version.to_s) >= Gem::Version.new('7')
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
       19 
24 
     | 
    
         
             
              def self.authorized?(controller, action, resource)
         
     | 
| 
       20 
25 
     | 
    
         
             
                @exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
         
     | 
| 
       21 
26 
     | 
    
         | 
| 
         @@ -120,7 +125,7 @@ module EffectiveResources 
     | 
|
| 
       120 
125 
     | 
    
         
             
                end
         
     | 
| 
       121 
126 
     | 
    
         
             
              end
         
     | 
| 
       122 
127 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
              def self.advance_date(date, business_days: 1, holidays: [: 
     | 
| 
      
 128 
     | 
    
         
            +
              def self.advance_date(date, business_days: 1, holidays: [:us, :observed])
         
     | 
| 
       124 
129 
     | 
    
         
             
                raise('business_days must be an integer <= 365') unless business_days.kind_of?(Integer) && business_days <= 365
         
     | 
| 
       125 
130 
     | 
    
         | 
| 
       126 
131 
     | 
    
         
             
                business_days.times do
         
     | 
| 
         @@ -133,7 +138,7 @@ module EffectiveResources 
     | 
|
| 
       133 
138 
     | 
    
         
             
                date
         
     | 
| 
       134 
139 
     | 
    
         
             
              end
         
     | 
| 
       135 
140 
     | 
    
         | 
| 
       136 
     | 
    
         
            -
              def self.business_day?(date, holidays: [: 
     | 
| 
      
 141 
     | 
    
         
            +
              def self.business_day?(date, holidays: [:us, :observed])
         
     | 
| 
       137 
142 
     | 
    
         
             
                require 'holidays' unless defined?(Holidays)
         
     | 
| 
       138 
143 
     | 
    
         
             
                date.wday != 0 && date.wday != 6 && Holidays.on(date, *holidays).blank?
         
     | 
| 
       139 
144 
     | 
    
         
             
              end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: effective_resources
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.18.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Code and Effect
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-11- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-11-28 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -16,14 +16,28 @@ dependencies: 
     | 
|
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - ">="
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version:  
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
24 
     | 
    
         
             
                - - ">="
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version:  
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: sprockets-rails
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       27 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
42 
     | 
    
         
             
              name: sqlite3
         
     | 
| 
       29 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -126,16 +140,16 @@ dependencies: 
     | 
|
| 
       126 
140 
     | 
    
         
             
              name: psych
         
     | 
| 
       127 
141 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       128 
142 
     | 
    
         
             
                requirements:
         
     | 
| 
       129 
     | 
    
         
            -
                - - " 
     | 
| 
      
 143 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       130 
144 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       131 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 145 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       132 
146 
     | 
    
         
             
              type: :development
         
     | 
| 
       133 
147 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       134 
148 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       135 
149 
     | 
    
         
             
                requirements:
         
     | 
| 
       136 
     | 
    
         
            -
                - - " 
     | 
| 
      
 150 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       137 
151 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       138 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 152 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       139 
153 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       140 
154 
     | 
    
         
             
              name: net-smtp
         
     | 
| 
       141 
155 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -274,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       274 
288 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       275 
289 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       276 
290 
     | 
    
         
             
            requirements: []
         
     | 
| 
       277 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 291 
     | 
    
         
            +
            rubygems_version: 3.4.10
         
     | 
| 
       278 
292 
     | 
    
         
             
            signing_key:
         
     | 
| 
       279 
293 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       280 
294 
     | 
    
         
             
            summary: Make any controller an effective resource controller.
         
     |