Class: Nginxbrew::Catalog
- Inherits:
-
Object
- Object
- Nginxbrew::Catalog
- Defined in:
- lib/nginxbrew/catalog.rb
Constant Summary collapse
- TypeNginx =
"nginx"
- TypeOpenresty =
"openresty"
- CacheExpireDays =
1
Instance Attribute Summary collapse
-
#ngx_type ⇒ Object
readonly
Returns the value of attribute ngx_type.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Class Method Summary collapse
Instance Method Summary collapse
- #filter_versions(head_of) ⇒ Object
- #head_of(version) ⇒ Object
-
#initialize(ngx_type, versions) ⇒ Catalog
constructor
A new instance of Catalog.
- #size ⇒ Object
- #unsupport_under!(version) ⇒ Object
Constructor Details
#initialize(ngx_type, versions) ⇒ Catalog
Returns a new instance of Catalog.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nginxbrew/catalog.rb', line 28 def initialize(ngx_type, versions) unless [TypeNginx, TypeOpenresty].include?(ngx_type) raise Exception.new("Invalid ngx_type #{ngx_type}") end raise Exception.new("No versions of nginx!") if versions.size == 0 @ngx_type = ngx_type @versions = versions.uniq.map do |v| Gem::Version.new(v) # 1.15.x <> 1.8.x should be 1.15.x > 1.8.x end.sort.reverse.map do |v| v.to_s end end |
Instance Attribute Details
#ngx_type ⇒ Object (readonly)
Returns the value of attribute ngx_type.
26 27 28 |
# File 'lib/nginxbrew/catalog.rb', line 26 def ngx_type @ngx_type end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
26 27 28 |
# File 'lib/nginxbrew/catalog.rb', line 26 def versions @versions end |
Class Method Details
.nginxes(cache_dir = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nginxbrew/catalog.rb', line 72 def self.nginxes(cache_dir=nil) catalog_cache_or(cache_dir, "nginxes") do versions = html_body_of("http://nginx.org", "/download/"). gsub(/href="nginx\-([0-9\.]+?)\.tar\.gz"/).inject([]) do |memo, match| memo << $1 memo end c = Catalog.new(TypeNginx, versions) c.unsupport_under!("0.5.38") # can not build under this version c end end |
.openresties(cache_dir = nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/nginxbrew/catalog.rb', line 85 def self.openresties(cache_dir=nil) catalog_cache_or(cache_dir, "openresties") do versions = html_body_of("http://openresty.org", "/"). gsub(/ngx_openresty\-([0-9\.]+?)\.tar\.gz/).inject([]) do |memo, match| memo << $1 memo end Catalog.new(TypeOpenresty, versions) end end |
Instance Method Details
#filter_versions(head_of) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/nginxbrew/catalog.rb', line 52 def filter_versions(head_of) src_numbers = head_of.split(".") src_numbers_size = src_numbers.size r = @versions.select do |v| v.split(".").slice(0, src_numbers_size) == src_numbers end raise VersionNotFoundError.new(head_of) if r.size == 0 r end |
#head_of(version) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/nginxbrew/catalog.rb', line 62 def head_of(version) src_numbers = version.split(".") src_numbers_size = src_numbers.size r = @versions.detect do |v| v.split(".").slice(0, src_numbers_size) == src_numbers end raise VersionNotFoundError.new(version) unless r r end |
#size ⇒ Object
48 49 50 |
# File 'lib/nginxbrew/catalog.rb', line 48 def size @versions.size end |
#unsupport_under!(version) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/nginxbrew/catalog.rb', line 41 def unsupport_under!(version) min_version = Gem::Version.new(version) @versions = @versions.select do |v| Gem::Version.new(v) >= min_version end end |