Sha256: d2d0aada82e802f2b59526f638f8446d3f1df5249f04a7ffdf7f6a25a3d80b56
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require('gems') require('active_support/all') module Thengem GemVersions = Struct.new( :date, :gem_name, :date_range, :major_release ) do def self.call(options) gem_name = options.fetch(:gem_name) date = if options.fetch(:date_string, nil) Date.parse(options.fetch(:date_string)) end date_range = options.fetch(:date_range, 6.months) major_release = options.fetch(:major_release, nil) new(date, gem_name, date_range, major_release).call end def call versions_in_range.map do |v| [v['number'], Date.parse(v['built_at']).strftime('%F')] end end private def versions_in_range versions.select { |v| include_version?(v) } end def versions @_versions ||= ::Gems.versions(gem_name) end def include_version?(version) if major_release return false unless version_belongs_to_major_release?(version) end if date return false unless version_in_date_range?(version) end true end def version_belongs_to_major_release?(version) /^#{major_release}/ =~ version['number'] end def version_in_date_range?(version) built_at = Date.parse(version['built_at']) built_at <= date && built_at >= gems_back_to end def gems_back_to @_gems_back_to ||= date - 6.months end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
thengem-0.1.1 | lib/thengem/gem_versions.rb |
thengem-0.1.0 | lib/thengem/gem_versions.rb |