Class: SystemBrowser::Services::GemService

Inherits:
AbstractService show all
Includes:
Helpers::BehaviourServiceHelper, Helpers::GemServiceHelper
Defined in:
lib/system_browser/services/gem_service.rb

Constant Summary collapse

CORE_LABEL =
'Ruby Core'
STDLIB_LABEL =
'Ruby Stdlib'
DEFAULT_GEMS =
[{name: CORE_LABEL}, {name: STDLIB_LABEL}]

Instance Method Summary collapse

Methods included from Helpers::BehaviourServiceHelper

#stdlib_behaviours

Methods included from Helpers::GemServiceHelper

#all_gems, #find_gem

Methods inherited from AbstractService

#initialize, service_name

Constructor Details

This class inherits a constructor from SystemBrowser::Services::AbstractService

Instance Method Details

#description(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

#getObject



8
9
10
11
# 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

#openObject



50
51
52
53
54
55
56
57
58
59
# 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