Sha256: 87fa7270e535749388914150186ea71af8721af8be3e7b24f29f427e53014f8d

Contents?: true

Size: 1.11 KB

Versions: 54

Compression:

Stored size: 1.11 KB

Contents

module Spree
  module Admin
    class Resource
      def initialize(controller_path, controller_name, parent_model, object_name = nil)
        @controller_path = controller_path
        @controller_name = controller_name
        @parent_model = parent_model
        @object_name = object_name
      end

      def sub_namespace_parts
        @controller_path.split('/')[2..-2]
      end

      def model_class
        sub_namespace = sub_namespace_parts.map { |s| s.capitalize }.join('::')
        sub_namespace = "#{sub_namespace}::" if sub_namespace.length > 0
        "Spree::#{sub_namespace}#{@controller_name.classify}".constantize
      end

      def model_name
        sub_namespace = sub_namespace_parts.join('/')
        sub_namespace = "#{sub_namespace}/" if sub_namespace.length > 0
        @parent_model.gsub("spree/#{sub_namespace}", '')
      end

      def object_name
        return @object_name if @object_name
        sub_namespace = sub_namespace_parts.join('_')
        sub_namespace = "#{sub_namespace}_" if sub_namespace.length > 0
        "#{sub_namespace}#{@controller_name.singularize}"
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
spree_backend-3.2.9 app/models/spree/admin/resource.rb
spree_backend-3.1.14 app/models/spree/admin/resource.rb
spree_backend-3.3.6 app/models/spree/admin/resource.rb
spree_backend-3.2.8 app/models/spree/admin/resource.rb
spree_backend-3.1.13 app/models/spree/admin/resource.rb
spree_backend-3.3.5 app/models/spree/admin/resource.rb
spree_backend-3.3.4 app/models/spree/admin/resource.rb
spree_backend-3.2.7 app/models/spree/admin/resource.rb
spree_backend-3.1.12 app/models/spree/admin/resource.rb
spree_backend-3.3.3 app/models/spree/admin/resource.rb
spree_backend-3.2.6 app/models/spree/admin/resource.rb
spree_backend-3.1.11 app/models/spree/admin/resource.rb
spree_backend-3.1.10 app/models/spree/admin/resource.rb
spree_backend-3.3.2 app/models/spree/admin/resource.rb
spree_backend-3.2.5 app/models/spree/admin/resource.rb
spree_backend-3.1.9 app/models/spree/admin/resource.rb
spree_backend-3.3.1 app/models/spree/admin/resource.rb
spree_backend-3.2.4 app/models/spree/admin/resource.rb
spree_backend-3.1.8 app/models/spree/admin/resource.rb
spree_backend-3.3.0 app/models/spree/admin/resource.rb