class GemContent

Find gems with defined content name in metadata and return pull path to the content

Copyright 2014 Michal Papis <mpapis@gmail.com>

See the file LICENSE for copying permission.

Constants

VERSION

Attributes

content_name[R]

@return [String] content name filter

Public Class Methods

get_gem_paths(content_name) click to toggle source

shortcut to initialize and get the paths in one line @param content_name [String] the path marker to read from gems metadata @return [Array<String>] all gems paths containing requested content

# File lib/gem-content.rb, line 16
def self.get_gem_paths(content_name)
  self.new(content_name).get_gem_paths
end
new(content_name) click to toggle source

initializes the filtered content path @param content_name [String] the path marker to read from gems metadata

# File lib/gem-content.rb, line 25
def initialize(content_name)
  @content_name = content_name
end

Public Instance Methods

get_gem_paths() click to toggle source

@return [Array<String>] all gems paths containing requested content

# File lib/gem-content.rb, line 30
def get_gem_paths
  active_or_latest_gems_matching.map do |specification|
    File.join(
      specification.full_gem_path,
      specification.metadata[content_name]
    )
  end
end

Private Instance Methods

active_or_latest_gem(params) click to toggle source

find active or latest gem in given set

# File lib/gem-content.rb, line 47
def active_or_latest_gem(params)
  _, specifications = params
  specifications.find(&:activated) or
  specifications.sort_by(&:version).last
end
active_or_latest_gems_matching() click to toggle source

filter active / latest gem versions

# File lib/gem-content.rb, line 42
def active_or_latest_gems_matching
  all_gems_matching.group_by(&:name).map(&method(:active_or_latest_gem))
end
all_gems() click to toggle source

get all gem specifications

# File lib/gem-content.rb, line 62
def all_gems
  Gem::Specification._all
end
all_gems_matching() click to toggle source

filter gems with content_name metadata

# File lib/gem-content.rb, line 54
def all_gems_matching
  all_gems.select do |specification|
    specification.metadata.is_a?(Hash) and
    specification.metadata[content_name]
  end
end