Sha256: 2d665b54b99cfc39d7b1d726f82b89592e99fa1835943acedc5e8ec114acb40d

Contents?: true

Size: 1.79 KB

Versions: 9

Compression:

Stored size: 1.79 KB

Contents

module ShopifyCli
  class ProjectType
    extend Feature::Set

    class << self
      attr_accessor :project_type,
        :project_name,
        :project_load_shallow

      def repository
        @repository ||= []
      end
      alias_method :all_loaded, :repository

      def inherited(klass)
        super
        repository << klass
        klass.project_type = @current_type
        klass.project_load_shallow = @shallow_load
      end

      def load_type(current_type, shallow = false)
        filepath = File.join(ShopifyCli::ROOT, "lib", "project_types", current_type.to_s, "cli.rb")
        return unless File.exist?(filepath)
        @shallow_load = shallow
        @current_type = current_type
        load(filepath)
        @current_type = nil
        @shallow_load = false
        for_app_type(current_type)
      end

      def load_all
        Dir.glob(File.join(ShopifyCli::ROOT, "lib", "project_types", "*", "cli.rb")).map do |filepath|
          load_type(filepath.split(File::Separator)[-2].to_sym, true)
        end
      end

      def for_app_type(type)
        repository.find { |k| k.project_type.to_s == type.to_s }
      end

      def project_filepath(path)
        File.join(ShopifyCli::PROJECT_TYPES_DIR, project_type.to_s, path)
      end

      def title(name)
        @project_name = name
      end

      def register_task(task, name)
        return if project_load_shallow
        ShopifyCli::Tasks.register(task, name)
      end

      def register_messages(messages)
        # Make sure we don't attempt to register a file more than once as that will fail
        @registered_message_files ||= {}
        return if @registered_message_files.key?(@project_type)
        @registered_message_files[@project_type] = true

        Context.load_messages(messages)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shopify-cli-2.4.0 lib/shopify-cli/project_type.rb
shopify-cli-2.3.0 lib/shopify-cli/project_type.rb
shopify-cli-2.2.2 lib/shopify-cli/project_type.rb
shopify-cli-2.2.1 lib/shopify-cli/project_type.rb
shopify-cli-2.2.0 lib/shopify-cli/project_type.rb
shopify-cli-2.1.0 lib/shopify-cli/project_type.rb
shopify-cli-2.0.2 lib/shopify-cli/project_type.rb
shopify-cli-2.0.1 lib/shopify-cli/project_type.rb
shopify-cli-2.0.0 lib/shopify-cli/project_type.rb