Class: GitCompound::DSL::ComponentDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/git_compound/dsl/component_dsl.rb

Overview

DSL for Component

Instance Method Summary collapse

Constructor Details

#initialize(component, &block) ⇒ ComponentDSL

Returns a new instance of ComponentDSL.



8
9
10
11
# File 'lib/git_compound/dsl/component_dsl.rb', line 8

def initialize(component, &block)
  @component = component
  instance_eval(&block)
end

Instance Method Details

#branch(component_branch) ⇒ Object



27
28
29
# File 'lib/git_compound/dsl/component_dsl.rb', line 27

def branch(component_branch)
  version_strategy(component_branch, Component::Version::Branch)
end

#destination(component_path) ⇒ Object



54
55
56
57
# File 'lib/git_compound/dsl/component_dsl.rb', line 54

def destination(component_path)
  @component.destination =
    Component::Destination.new(component_path, @component)
end

#sha(component_sha) ⇒ Object



35
36
37
38
39
40
# File 'lib/git_compound/dsl/component_dsl.rb', line 35

def sha(component_sha)
  raise CompoundSyntaxError, 'Invalid SHA1 format' unless
    component_sha.match(/[0-9a-f]{5,40}/)

  version_strategy(component_sha, Component::Version::SHA)
end

#source(component_source, *source_options) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/git_compound/dsl/component_dsl.rb', line 42

def source(component_source, *source_options)
  raise CompoundSyntaxError,
        'Version/branch/tag/sha needed first' unless @version

  @component.source =
    Component::Source.new(component_source,
                          @version,
                          @version_strategy,
                          source_options,
                          @component)
end

#tag(component_tag) ⇒ Object



31
32
33
# File 'lib/git_compound/dsl/component_dsl.rb', line 31

def tag(component_tag)
  version_strategy(component_tag, Component::Version::Tag)
end

#version(component_version) ⇒ Object



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

def version(component_version)
  version_strategy(component_version, Component::Version::GemVersion)
end

#version_strategy(version, strategy) ⇒ Object

Custom version strategy, also available via DSL



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

def version_strategy(version, strategy)
  raise CompoundSyntaxError,
        'Version strategy already set !' if @version_strategy

  @version = version
  @version_strategy = strategy
end