avo 2.9.1.pre1 → 2.9.1.pre2
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.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/avo/base_resource.rb +4 -12
- data/lib/avo/concerns/model_class_constantized.rb +23 -0
- data/lib/avo/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9401cff40f8b21f28409534ff2540ef6deb94620952b75ede2df8c2a38dfd81f
         | 
| 4 | 
            +
              data.tar.gz: 20c4c6e211d46e6818879d26e82619d96eb8639804c84fe35e1a94c168655e5f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b053e8998efda171728723c33b725098962df7b64a4b62d2d59c4f6f094039e96bb9eb38d848a076d3cf4df8faa6dbe6f97d2e9de58f81b8601158441178c0dc
         | 
| 7 | 
            +
              data.tar.gz: 9d65eb151f122ddd4b34fbc775e9dc9765efc30364c49d6ba2b079f4435d8d062b2181b927dc8d7f22cb84a1d808d31f9b4c49ced3c612b566a363e1e45b6b1c
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/avo/base_resource.rb
    CHANGED
    
    | @@ -8,6 +8,7 @@ module Avo | |
| 8 8 | 
             
                include Avo::Concerns::HasModel
         | 
| 9 9 | 
             
                include Avo::Concerns::HasFields
         | 
| 10 10 | 
             
                include Avo::Concerns::HasStimulusControllers
         | 
| 11 | 
            +
                include Avo::Concerns::ModelClassConstantized
         | 
| 11 12 |  | 
| 12 13 | 
             
                delegate :view_context, to: ::Avo::App
         | 
| 13 14 | 
             
                delegate :simple_format, :content_tag, to: :view_context
         | 
| @@ -29,7 +30,6 @@ module Avo | |
| 29 30 | 
             
                class_attribute :search_query, default: nil
         | 
| 30 31 | 
             
                class_attribute :search_query_help, default: ""
         | 
| 31 32 | 
             
                class_attribute :includes, default: []
         | 
| 32 | 
            -
                class_attribute :model_class
         | 
| 33 33 | 
             
                class_attribute :translation_key
         | 
| 34 34 | 
             
                class_attribute :default_view_type, default: :table
         | 
| 35 35 | 
             
                class_attribute :devise_password_optional, default: false
         | 
| @@ -78,14 +78,14 @@ module Avo | |
| 78 78 |  | 
| 79 79 | 
             
                  # This resolves the scope when doing "where" queries (not find queries)
         | 
| 80 80 | 
             
                  def query_scope
         | 
| 81 | 
            -
                    final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class:  | 
| 81 | 
            +
                    final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class: model_class) : model_class
         | 
| 82 82 |  | 
| 83 83 | 
             
                    authorization.apply_policy final_scope
         | 
| 84 84 | 
             
                  end
         | 
| 85 85 |  | 
| 86 86 | 
             
                  # This resolves the scope when finding records (not "where" queries)
         | 
| 87 87 | 
             
                  def find_scope
         | 
| 88 | 
            -
                    final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class:  | 
| 88 | 
            +
                    final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class: model_class) : model_class
         | 
| 89 89 |  | 
| 90 90 | 
             
                    authorization.apply_policy final_scope
         | 
| 91 91 | 
             
                  end
         | 
| @@ -99,14 +99,6 @@ module Avo | |
| 99 99 |  | 
| 100 100 | 
             
                    ordering.dig(:actions) || {}
         | 
| 101 101 | 
             
                  end
         | 
| 102 | 
            -
             | 
| 103 | 
            -
                  def get_model_class
         | 
| 104 | 
            -
                    if model_class.is_a? String
         | 
| 105 | 
            -
                      model_class.safe_constantize
         | 
| 106 | 
            -
                    else
         | 
| 107 | 
            -
                      model_class
         | 
| 108 | 
            -
                    end
         | 
| 109 | 
            -
                  end
         | 
| 110 102 | 
             
                end
         | 
| 111 103 |  | 
| 112 104 | 
             
                def initialize
         | 
| @@ -260,7 +252,7 @@ module Avo | |
| 260 252 |  | 
| 261 253 | 
             
                def model_class
         | 
| 262 254 | 
             
                  # get the model class off of the static property
         | 
| 263 | 
            -
                  return self.class. | 
| 255 | 
            +
                  return self.class.model_class if self.class.model_class.present?
         | 
| 264 256 |  | 
| 265 257 | 
             
                  # get the model class off of the model
         | 
| 266 258 | 
             
                  return @model.base_class if @model.present?
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            module Avo
         | 
| 2 | 
            +
              module Concerns
         | 
| 3 | 
            +
                module ModelClassConstantized
         | 
| 4 | 
            +
                  extend ActiveSupport::Concern
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  class_methods do
         | 
| 7 | 
            +
                    attr_reader :model_class
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    # Cast the model class to a constantized version and memoize it like that
         | 
| 10 | 
            +
                    def model_class=(value)
         | 
| 11 | 
            +
                      @model_class = case value
         | 
| 12 | 
            +
                      when Class
         | 
| 13 | 
            +
                        value
         | 
| 14 | 
            +
                      when String, Symbol
         | 
| 15 | 
            +
                        value.to_s.safe_constantize
         | 
| 16 | 
            +
                      else
         | 
| 17 | 
            +
                        raise ArgumentError.new "Failed to find a proper model class for #{self.to_s}"
         | 
| 18 | 
            +
                      end
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
    
        data/lib/avo/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: avo
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.9.1. | 
| 4 | 
            +
              version: 2.9.1.pre2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Adrian Marin
         | 
| @@ -1179,6 +1179,7 @@ files: | |
| 1179 1179 | 
             
            - lib/avo/concerns/has_model.rb
         | 
| 1180 1180 | 
             
            - lib/avo/concerns/has_stimulus_controllers.rb
         | 
| 1181 1181 | 
             
            - lib/avo/concerns/has_tools.rb
         | 
| 1182 | 
            +
            - lib/avo/concerns/model_class_constantized.rb
         | 
| 1182 1183 | 
             
            - lib/avo/configuration.rb
         | 
| 1183 1184 | 
             
            - lib/avo/dashboards/base_dashboard.rb
         | 
| 1184 1185 | 
             
            - lib/avo/dashboards/base_divider.rb
         |