Class: GitCompound::Component

Inherits:
Node
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/git_compound.rb,
lib/git_compound/component.rb,
lib/git_compound/component/source.rb,
lib/git_compound/component/destination.rb,
lib/git_compound/component/version/sha.rb,
lib/git_compound/component/version/tag.rb,
lib/git_compound/component/version/branch.rb,
lib/git_compound/component/version/gem_version.rb,
lib/git_compound/component/version/version_strategy.rb

Overview

Component

Defined Under Namespace

Modules: Version Classes: Destination, Source

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from Node

#ancestors

Constructor Details

#initialize(name, parent = nil, &block) ⇒ Component

Returns a new instance of Component.



15
16
17
18
19
20
21
# File 'lib/git_compound/component.rb', line 15

def initialize(name, parent = nil, &block)
  @name   = name
  @parent = parent
  DSL::ComponentDSL.new(self, &block) if block
  raise CompoundSyntaxError, "No block given for component `#{@name}`" unless block
  raise GitCompoundError, "Component `#{@name}` invalid" unless valid?
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



13
14
15
# File 'lib/git_compound/component.rb', line 13

def destination
  @destination
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/git_compound/component.rb', line 12

def name
  @name
end

#sourceObject

Returns the value of attribute source.



13
14
15
# File 'lib/git_compound/component.rb', line 13

def source
  @source
end

Instance Method Details

#==(other) ⇒ Object



61
62
63
# File 'lib/git_compound/component.rb', line 61

def ==(other)
  origin == other.origin || manifest == other.manifest
end

#build!Object



36
37
38
39
40
41
# File 'lib/git_compound/component.rb', line 36

def build!
  @source.clone(path)
  @destination.repository do |repo|
    repo.checkout(@source.ref)
  end
end

#manifestObject



32
33
34
# File 'lib/git_compound/component.rb', line 32

def manifest
  @manifest ||= @source.manifest
end

#process(*workers) ⇒ Object



27
28
29
30
# File 'lib/git_compound/component.rb', line 27

def process(*workers)
  workers.each { |worker| worker.visit_component(self) }
  @manifest.process(*workers) if manifest
end

#remove!Object

Raises:



52
53
54
55
56
57
58
59
# File 'lib/git_compound/component.rb', line 52

def remove!
  raise GitCompoundError, 'Risky directory !' if
    path.start_with?('/') || path.include?('..')
  raise GitCompoundError, 'Not a directory !' unless
    File.directory?(path)

  FileUtils.remove_entry_secure(path)
end

#to_hashObject



65
66
67
68
69
70
71
# File 'lib/git_compound/component.rb', line 65

def to_hash
  { name: @name,
    sha:  @source.sha,
    source: @source.origin,
    destination: @destination.path
  }
end

#update!Object



43
44
45
46
47
48
49
50
# File 'lib/git_compound/component.rb', line 43

def update!
  @destination.repository do |repo|
    repo.fetch
    repo.checkout(@source.ref)
    repo.fetch
    repo.merge if repo.branch?(@source.ref)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/git_compound/component.rb', line 23

def valid?
  [@name, @source, @destination].all?
end