snfoil 0.4.3 → 0.5.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/lib/sn_foil/contexts/build_context.rb +2 -2
- data/lib/sn_foil/contexts/create_context.rb +2 -2
- data/lib/sn_foil/contexts/destroy_context.rb +2 -2
- data/lib/sn_foil/contexts/index_context.rb +2 -2
- data/lib/sn_foil/contexts/setup_context.rb +8 -8
- data/lib/sn_foil/contexts/show_context.rb +2 -2
- data/lib/sn_foil/contexts/update_context.rb +2 -2
- data/lib/sn_foil/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8243d9d711a164c99818bd9217d002a4bbeda113d6c68d45dad064bea6a04618
         | 
| 4 | 
            +
              data.tar.gz: 53c8ee7b0b44bf7411eb98aebb23793ebf5dd69fab16a278abb2895062edabc6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 25527b584b0d1c3360ef226ecf16a4934ae209bbc96aed912f4131b056303a16e4bdbdfd801fb0adb2b1d2b47ec120e021990c764fb9ca34886269d68804d921
         | 
| 7 | 
            +
              data.tar.gz: 67e8a71e82d49cc5fe3aa45b4fad9140cb234f3d48151af1930279b9109603dcece1bbdbecfe8dd8fe1d99c11252e01ae454435184b3e4e8c34754f6b877de8a
         | 
| @@ -17,8 +17,8 @@ module SnFoil | |
| 17 17 | 
             
                  class_methods do
         | 
| 18 18 | 
             
                    attr_reader :i_setup_create_hooks, :i_before_create_hooks, :i_after_create_hooks,
         | 
| 19 19 | 
             
                                :i_after_create_success_hooks, :i_after_create_failure_hooks
         | 
| 20 | 
            -
                    def create(params:,  | 
| 21 | 
            -
                      new( | 
| 20 | 
            +
                    def create(params:, entity: nil, **options)
         | 
| 21 | 
            +
                      new(entity).create(**options, params: params)
         | 
| 22 22 | 
             
                    end
         | 
| 23 23 |  | 
| 24 24 | 
             
                    def setup_create(method = nil, **options, &block)
         | 
| @@ -17,8 +17,8 @@ module SnFoil | |
| 17 17 | 
             
                  class_methods do
         | 
| 18 18 | 
             
                    attr_reader :i_setup_destroy_hooks, :i_before_destroy_hooks, :i_after_destroy_hooks,
         | 
| 19 19 | 
             
                                :i_after_destroy_success_hooks, :i_after_destroy_failure_hooks
         | 
| 20 | 
            -
                    def destroy(id:,  | 
| 21 | 
            -
                      new( | 
| 20 | 
            +
                    def destroy(id:, entity: nil, **options)
         | 
| 21 | 
            +
                      new(entity).destroy(**options, id: id)
         | 
| 22 22 | 
             
                    end
         | 
| 23 23 |  | 
| 24 24 | 
             
                    def setup_destroy(method = nil, **options, &block)
         | 
| @@ -15,8 +15,8 @@ module SnFoil | |
| 15 15 | 
             
                  class_methods do
         | 
| 16 16 | 
             
                    attr_reader :i_searcher, :i_setup_index_hooks
         | 
| 17 17 |  | 
| 18 | 
            -
                    def index(params: {},  | 
| 19 | 
            -
                      new( | 
| 18 | 
            +
                    def index(params: {}, entity: nil, **options)
         | 
| 19 | 
            +
                      new(entity).index(**options, params: params)
         | 
| 20 20 | 
             
                    end
         | 
| 21 21 |  | 
| 22 22 | 
             
                    def searcher(klass = nil)
         | 
| @@ -42,13 +42,13 @@ module SnFoil | |
| 42 42 | 
             
                    self.class.i_setup_hooks || []
         | 
| 43 43 | 
             
                  end
         | 
| 44 44 |  | 
| 45 | 
            -
                  attr_reader : | 
| 46 | 
            -
                  def initialize( | 
| 47 | 
            -
                    @ | 
| 45 | 
            +
                  attr_reader :entity
         | 
| 46 | 
            +
                  def initialize(entity = nil)
         | 
| 47 | 
            +
                    @entity = entity
         | 
| 48 48 | 
             
                  end
         | 
| 49 49 |  | 
| 50 50 | 
             
                  def authorize(object, action, **options)
         | 
| 51 | 
            -
                    return unless  | 
| 51 | 
            +
                    return unless entity # Add logging
         | 
| 52 52 |  | 
| 53 53 | 
             
                    policy = lookup_policy(object, options)
         | 
| 54 54 | 
             
                    raise Pundit::NotAuthorizedError, query: action, record: object, policy: policy unless policy.public_send(action)
         | 
| @@ -59,7 +59,7 @@ module SnFoil | |
| 59 59 | 
             
                  def scope(object_class = nil, **options)
         | 
| 60 60 | 
             
                    object_class ||= model
         | 
| 61 61 | 
             
                    policy_name = lookup_policy(object_class, options).class.name
         | 
| 62 | 
            -
                    "#{policy_name}::Scope".safe_constantize.new(wrap_object(object_class),  | 
| 62 | 
            +
                    "#{policy_name}::Scope".safe_constantize.new(wrap_object(object_class), entity)
         | 
| 63 63 | 
             
                  end
         | 
| 64 64 |  | 
| 65 65 | 
             
                  def wrap_object(object)
         | 
| @@ -103,11 +103,11 @@ module SnFoil | |
| 103 103 |  | 
| 104 104 | 
             
                  def lookup_policy(object, options)
         | 
| 105 105 | 
             
                    lookup = if options[:policy]
         | 
| 106 | 
            -
                               options[:policy].new( | 
| 106 | 
            +
                               options[:policy].new(entity, object)
         | 
| 107 107 | 
             
                             elsif policy
         | 
| 108 | 
            -
                               policy.new( | 
| 108 | 
            +
                               policy.new(entity, object)
         | 
| 109 109 | 
             
                             else
         | 
| 110 | 
            -
                               Pundit.policy!( | 
| 110 | 
            +
                               Pundit.policy!(entity, object)
         | 
| 111 111 | 
             
                             end
         | 
| 112 112 |  | 
| 113 113 | 
             
                    lookup.options = options if lookup.respond_to? :options=
         | 
| @@ -15,8 +15,8 @@ module SnFoil | |
| 15 15 | 
             
                  class_methods do
         | 
| 16 16 | 
             
                    attr_reader :i_setup_show_hooks
         | 
| 17 17 |  | 
| 18 | 
            -
                    def show(id:,  | 
| 19 | 
            -
                      new( | 
| 18 | 
            +
                    def show(id:, entity: nil, **options)
         | 
| 19 | 
            +
                      new(entity).show(**options, id: id)
         | 
| 20 20 | 
             
                    end
         | 
| 21 21 |  | 
| 22 22 | 
             
                    def setup_show(method = nil, **options, &block)
         | 
| @@ -17,8 +17,8 @@ module SnFoil | |
| 17 17 | 
             
                  class_methods do
         | 
| 18 18 | 
             
                    attr_reader :i_setup_update_hooks, :i_before_update_hooks, :i_after_update_hooks,
         | 
| 19 19 | 
             
                                :i_after_update_success_hooks, :i_after_update_failure_hooks
         | 
| 20 | 
            -
                    def update(id:, params:,  | 
| 21 | 
            -
                      new( | 
| 20 | 
            +
                    def update(id:, params:, entity: nil, **options)
         | 
| 21 | 
            +
                      new(entity).update(**options, id: id, params: params)
         | 
| 22 22 | 
             
                    end
         | 
| 23 23 |  | 
| 24 24 | 
             
                    def setup_update(method = nil, **options, &block)
         | 
    
        data/lib/sn_foil/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: snfoil
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.5.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Matthew Howes
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2020- | 
| 12 | 
            +
            date: 2020-04-16 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activesupport
         |