Sha256: fd518f3c515d781d326fae1bdf31131f10677645685cc4cb07446013a4de7906

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module ShopifyCLI
  module Theme
    class Syncer
      class Operation
        attr_accessor :method, :file

        COLOR_BY_STATUS = {
          error: :red,
          synced: :green,
          fixed: :cyan,
        }

        def initialize(ctx, method, file)
          @ctx = ctx
          @method = method
          @file = file
        end

        def to_s
          "#{method} #{file_path}"
        end

        def as_error_message
          as_message_with(status: :error)
        end

        def as_synced_message
          as_message_with(status: :synced)
        end

        def as_fix_message
          as_message_with(status: :fixed)
        end

        def file_path
          file&.relative_path.to_s
        end

        private

        def as_message_with(status:)
          status_color = COLOR_BY_STATUS[status]
          status_text = @ctx.message("theme.serve.operation.status.#{status}").ljust(6)

          "#{timestamp} {{#{status_color}:#{status_text}}} {{>}} {{blue:#{self}}}"
        end

        def timestamp
          Time.now.strftime("%T")
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
shopify-cli-2.15.1 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.15.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.14.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.13.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.12.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.11.2 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.11.1 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.11.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.10.2 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.10.1 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.10.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.9.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.8.0 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.7.4 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.7.3 lib/shopify_cli/theme/syncer/operation.rb
shopify-cli-2.7.2 lib/shopify_cli/theme/syncer/operation.rb