class SystemBrowser::Services::GemService

Constants

CORE_LABEL
DEFAULT_GEMS
STDLIB_LABEL

Public Instance Methods

description(*args) click to toggle source
# File lib/system_browser/services/gem_service.rb, line 13
      def description(*args)
        gem = self.find_gem(@data)

        case @data
        when CORE_LABEL
          desc = <<DESC
Ruby Core-#{RUBY_VERSION}
===
The Ruby Core defines common Ruby behaviours available to every program.
DESC

          {
            description: desc,
            behaviours: self.count_behaviours(CoreClasses.as_set),
            development_deps: [],
            runtime_deps: [],
          }
        when STDLIB_LABEL
          desc = <<DESC
Ruby Standard Library-#{RUBY_VERSION}
===
The Ruby Standard Library is a vast collection of classes and modules that you can require in your code for additional features. System Browser shows only those behaviours that were required by this Ruby process.
DESC
          {
            description: desc,
            behaviours: self.count_behaviours(self.stdlib_behaviours),
            development_deps: [],
            runtime_deps: []
          }
        else
          gemdata = Gem2Markdown.convert(gem)
          behs = BehaviourService.all_from(gem.name)
          gemdata[:behaviours] = count_behaviours(behs)
          gemdata
        end
      end
get() click to toggle source
# File lib/system_browser/services/gem_service.rb, line 8
def get
  gems = self.all_gems.map { |gem| {name: gem.first} }
  [*DEFAULT_GEMS, *gems]
end
open() click to toggle source
# File lib/system_browser/services/gem_service.rb, line 50
def open
  editor = [ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
  path = self.find_gem(@data).full_gem_path

  command = [*Shellwords.split(editor), path]

  system(*command)

  :ok
end

Protected Instance Methods

count_behaviours(collection) click to toggle source
# File lib/system_browser/services/gem_service.rb, line 66
def count_behaviours(collection)
  behaviours = {}

  grouped = collection.group_by(&:class)

  exceptions = (grouped[Class] || []).group_by do |beh|
    beh.ancestors.include?(Exception)
  end

  behaviours['modules'] = (grouped[Module] || []).count
  behaviours['classes'] = (exceptions[false] || []).count
  behaviours['exceptions'] = (exceptions[true] || []).count

  behaviours
end