Class: Yoda::Store::Objects::Library::Gem

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/yoda/store/objects/library/gem.rb

Defined Under Namespace

Classes: Connected

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

#==, #derive, #eql?, #hash, included, #to_json

Constructor Details

#initialize(name:, version:, source_path:, full_gem_path:, doc_dir:, source_type:) ⇒ Gem

Returns a new instance of Gem.



60
61
62
63
64
65
66
67
# File 'lib/yoda/store/objects/library/gem.rb', line 60

def initialize(name:, version:, source_path:, full_gem_path:, doc_dir:, source_type:)
  @name = name
  @version = version
  @source_path = source_path
  @full_gem_path = full_gem_path
  @doc_dir = doc_dir
  @source_type = source_type&.to_sym
end

Instance Attribute Details

#doc_dirString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/store/objects/library/gem.rb', line 9

def doc_dir
  @doc_dir
end

#full_gem_pathString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/store/objects/library/gem.rb', line 9

def full_gem_path
  @full_gem_path
end

#nameString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/store/objects/library/gem.rb', line 9

def name
  @name
end

#source_pathString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/store/objects/library/gem.rb', line 9

def source_path
  @source_path
end

#source_typeSymbol? (readonly)

Returns:

  • (Symbol, nil)


12
13
14
# File 'lib/yoda/store/objects/library/gem.rb', line 12

def source_type
  @source_type
end

#versionString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/store/objects/library/gem.rb', line 9

def version
  @version
end

Class Method Details

.from_gem_spec(spec) ⇒ Object

Parameters:

  • spec (Bundler::LazySpecification)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yoda/store/objects/library/gem.rb', line 16

def from_gem_spec(spec)
  if spec.respond_to?(:full_gem_path)
    # Installed
    new(
      name: spec.name,
      version: spec.version.version,
      source_path: spec.source.respond_to?(:path) ? spec.source.path : nil,
      full_gem_path: spec.full_gem_path,
      doc_dir: spec.doc_dir,
      source_type: source_type_of(spec.source),
    )
  else
    # Not installed
    new(
      name: spec.name,
      version: spec.version.version,
      source_path: nil,
      full_gem_path: nil,
      doc_dir: nil,
      source_type: nil,
    )
  end
end

.source_type_of(source) ⇒ Symbol?

Parameters:

  • source (Bundler::Source, nil)

Returns:

  • (Symbol, nil)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/yoda/store/objects/library/gem.rb', line 42

def source_type_of(source)
  return nil unless source

  case source
  when Bundler::Source::Git
    :git
  when Bundler::Source::Gemspec
    :gemspec
  when Bundler::Source::Rubygems
    :rubygems
  when Bundler::Source::Path
    :path
  else
    nil
  end
end

Instance Method Details

#idObject



69
70
71
# File 'lib/yoda/store/objects/library/gem.rb', line 69

def id
  "#{name}:#{version}"
end

#installed?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/yoda/store/objects/library/gem.rb', line 89

def installed?
  full_gem_path && File.exists?(full_gem_path)
end

#local?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/yoda/store/objects/library/gem.rb', line 73

def local?
  source_path
end

#managed_by_rubygems?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/yoda/store/objects/library/gem.rb', line 93

def managed_by_rubygems?
  source_type == :rubygems
end

#to_hObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/yoda/store/objects/library/gem.rb', line 77

def to_h
  {
    name: name,
    version: version,
    source_path: source_path,
    full_gem_path: full_gem_path,
    doc_dir: doc_dir,
    source_type: source_type,
  }
end

#with_project_connection(**kwargs) ⇒ Connected

Returns:



98
99
100
# File 'lib/yoda/store/objects/library/gem.rb', line 98

def with_project_connection(**kwargs)
  self.class.const_get(:Connected).new(self, **kwargs)
end