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.12.4 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.12.3 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.12.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.12.1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.12.0 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.11.4 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.11.3 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.11.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.11.1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.11.0 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.10.0 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.9.4 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.9.3.3 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.9.3.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.9.3.1 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.9.2 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.9.0 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.15 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.14 app/controllers/concerns/para/admin/resource_controller_concerns.rb
para-0.8.13 app/controllers/concerns/para/admin/resource_controller_concerns.rb