class Simp::Metadata::Location

Attributes

component[RW]
location[RW]
locationinfo[RW]

Public Class Methods

new(locationinfo, location, component) click to toggle source
# File lib/simp/metadata/location.rb, line 9
def initialize(locationinfo, location, component)
  @locationinfo = locationinfo
  @location = location
  @component = component
end

Public Instance Methods

[](index) click to toggle source
# File lib/simp/metadata/location.rb, line 31
def [](index)
  send index.to_sym
end
each() { |key, self| ... } click to toggle source
# File lib/simp/metadata/location.rb, line 35
def each
  keys.each do |key|
    yield key, self[key]
  end
end
extract() click to toggle source
# File lib/simp/metadata/location.rb, line 41
def extract
  if location.key?('extract')
    location['extract']
  else
    false
  end
end
keys() click to toggle source
# File lib/simp/metadata/location.rb, line 27
def keys
  %w(extract primary method type url)
end
method() click to toggle source
# File lib/simp/metadata/location.rb, line 53
def method
  if @local_method
    @local_method
  else
    if location.key?('type')
      if location['type'] == 'git'
        'git'
      else
        'file'
      end
    else
      if location.key?('method')
        location['method']
      else
        'file'
      end
    end
  end
end
method=(value) click to toggle source
# File lib/simp/metadata/location.rb, line 49
def method=(value)
  @local_method = value
end
primary() click to toggle source
# File lib/simp/metadata/location.rb, line 19
def primary
  if location.key?('primary')
    location['primary']
  else
    false
  end
end
real_url() click to toggle source
# File lib/simp/metadata/location.rb, line 166
def real_url
  if component.compiled?
    case component.component_type
    when 'rubygem'
      case component.release_source.to_s
      when 'simp-metadata'
        return "simp:///#{component.name}/#{component.binaryname}"
      when 'enterprise-metadata'
        return "simp-enterprise:///#{component.name}/#{component.binaryname}"
      end
    end
  end
  if location.key?('url')
    location['url']
  else
    if location.key?('host')
      if location.key?('path')
        if location.key?('type')
          "https://#{location['host']}/#{location['path']}"
        end
      end
    end
  end
end
to_s() click to toggle source
# File lib/simp/metadata/location.rb, line 15
def to_s
  url
end
type() click to toggle source
# File lib/simp/metadata/location.rb, line 73
def type
  location['binary']
end
url() click to toggle source
# File lib/simp/metadata/location.rb, line 81
def url
  if @local_url
    @local_url
  else
    base = real_url
    uri = Simp::Metadata.uri(base)
    case uri.scheme
    when 'simp-enterprise'
      if uri.query.class == String
        query_elements = uri.query.split('&')
        newquery = []
        found_version = false
        found_filetype = false
        query_elements.each do |element|
          elements = element.split('=')
          if elements.size > 1
            if elements[0] == 'version'
              found_version = true
              elements[1] = component.version
              newquery << elements.join('=')
            elsif elements[0] == 'filetype'
              found_filetype = true
              elements[1] = component.extension
              newquery << elements.join('=')
            else
              newquery << element
            end
          else
            newquery << element
          end
        end
        newquery << "version=#{component.version}" unless found_version

        unless found_filetype
          newquery << "filetype=#{component.extension}"
        end

        uri.query = newquery.join('&')
      end
      uri.to_s

    when 'simp'
      if uri.query.class == String
        query_elements = uri.query.split('&')
        newquery = []
        found_version = false
        found_filetype = false
        query_elements.each do |element|
          elements = element.split('=')
          if elements.size > 1
            if elements[0] == 'version'
              found_version = true
              elements[1] = component.version
              newquery << elements.join('=')
            elsif elements[0] == 'filetype'
              found_filetype = true
              elements[1] = component.extension
              newquery << elements.join('=')
            else
              newquery << element
            end
          else
            newquery << element
          end
        end
        newquery << "version=#{component.version}" unless found_version
        unless found_filetype
          newquery << "filetype=#{component.extension}"
        end
        uri.query = newquery.join('&')
      end
      uri.to_s
    else
      case component.component_type
      when 'rubygem'
        if base =~ /.*\.gem/
        else
          "#{base}/#{component.asset_name}-#{component.version}.gem"
        end
      end
      base
    end
  end
end
url=(value) click to toggle source
# File lib/simp/metadata/location.rb, line 77
def url=(value)
  @local_url = value
end