Sha256: db0c96d00e72552e5a3248caf89cea81b3bc0a3d290b6ab018ddfecce9647a05

Contents?: true

Size: 1.1 KB

Versions: 33

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

class VolumeParserService
  class << self
    def parse(volumes)
      return [] if volumes.empty?

      Uffizzi.ui.say("Volumes '#{volumes}' should be an array") unless volumes.is_a?(Array)

      volumes.map { |volume| parse_volume(volume) }
    end

    private

    def parse_volume(volume)
      case volume
      when String
        process_short_syntax(volume)
      when Hash
        process_long_syntax(volume)
      else
        Uffizzi.ui.say("Unsupported type of '#{volumes}' option")
      end
    end

    def process_short_syntax(volume_data)
      path_part1, path_part2 = volume_data.split(':').map(&:strip)

      path_part1 if host_volume?(path_part1, path_part2)
    end

    def process_long_syntax(volume_data)
      source_path = volume_data['source'].to_s.strip
      target_path = volume_data['target'].to_s.strip

      source_path if host_volume?(source_path, target_path)
    end

    def host_volume?(source_path, target_path)
      path?(source_path) && path?(target_path)
    end

    def path?(path)
      path.to_s.start_with?('/', './', '../')
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
uffizzi-cli-2.4.11 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.10 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.9 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.8 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.7 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.6 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.5 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.4 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.3 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.2 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.1 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.4.0 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.3.4 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.3.3 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.3.2 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.3.1 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.3.0 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.2.2 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.2.1 lib/uffizzi/services/volume_parser_service.rb
uffizzi-cli-2.2.0 lib/uffizzi/services/volume_parser_service.rb