Sha256: bc9fc4d55e7e305b19488ff12653e67960cc8badadd81d72ed462cd60937e6b0

Contents?: true

Size: 966 Bytes

Versions: 49

Compression:

Stored size: 966 Bytes

Contents

module Para
  module Admin
    module ResourceControllerConcerns
      extend ActiveSupport::Concern

      included do
        before_action :set_resource_model_from_resource
      end

      private

      def set_resource_model_from_resource
        @resource_model = resource.class if resource
      end

      def resource_model
        @resource_model ||= @component.try(:model)
      end

      def resource
        @resource ||= begin
          resource = instance_variable_get(:"@#{ resource_name }") if resource_name
          # We ensure that the fetched resource is not a relation, which could
          # happen for uncountable resource names (like "news") and would make
          # code depending on the `resource` getter to fail unexpectedly
          resource unless ActiveRecord::Relation === resource
        end
      end

      def resource_name
        resource_model.model_name.singular_route_key if resource_model
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
para-0.8.12 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.11 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.10 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.9 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.8 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.7 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.5 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.3.3 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.3.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.3.1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.3 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.2.3 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.2.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.2.1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.0 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.7.4.p1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.7.4 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.7.3.p6 app/controllers/concerns/para/admin/resource_controller_concerns.rb