Class: Simp::Metadata::Location
- Inherits:
-
Object
- Object
- Simp::Metadata::Location
- Defined in:
- lib/simp/metadata/location.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
Returns the value of attribute component.
-
#location ⇒ Object
Returns the value of attribute location.
-
#locationinfo ⇒ Object
Returns the value of attribute locationinfo.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
- #extract ⇒ Object
-
#initialize(locationinfo, location, component) ⇒ Location
constructor
A new instance of Location.
- #keys ⇒ Object
- #method ⇒ Object
- #method=(value) ⇒ Object
- #primary ⇒ Object
- #real_url ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
- #url ⇒ Object
- #url=(value) ⇒ Object
Constructor Details
#initialize(locationinfo, location, component) ⇒ Location
Returns a new instance of Location.
9 10 11 12 13 |
# File 'lib/simp/metadata/location.rb', line 9 def initialize(locationinfo, location, component) @locationinfo = locationinfo @location = location @component = component end |
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component.
7 8 9 |
# File 'lib/simp/metadata/location.rb', line 7 def component @component end |
#location ⇒ Object
Returns the value of attribute location.
6 7 8 |
# File 'lib/simp/metadata/location.rb', line 6 def location @location end |
#locationinfo ⇒ Object
Returns the value of attribute locationinfo.
5 6 7 |
# File 'lib/simp/metadata/location.rb', line 5 def locationinfo @locationinfo end |
Instance Method Details
#[](index) ⇒ Object
31 32 33 |
# File 'lib/simp/metadata/location.rb', line 31 def [](index) send index.to_sym end |
#each ⇒ Object
35 36 37 38 39 |
# File 'lib/simp/metadata/location.rb', line 35 def each keys.each do |key| yield key, self[key] end end |
#extract ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/simp/metadata/location.rb', line 41 def extract if location.key?('extract') location['extract'] else false end end |
#keys ⇒ Object
27 28 29 |
# File 'lib/simp/metadata/location.rb', line 27 def keys %w(extract primary method type url) end |
#method ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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) ⇒ Object
49 50 51 |
# File 'lib/simp/metadata/location.rb', line 49 def method=(value) @local_method = value end |
#primary ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/simp/metadata/location.rb', line 19 def primary if location.key?('primary') location['primary'] else false end end |
#real_url ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/simp/metadata/location.rb', line 15 def to_s url end |
#type ⇒ Object
73 74 75 |
# File 'lib/simp/metadata/location.rb', line 73 def type location['binary'] end |
#url ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# 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) ⇒ Object
77 78 79 |
# File 'lib/simp/metadata/location.rb', line 77 def url=(value) @local_url = value end |