Class: GTA::Stage

Inherits:
Object
  • Object
show all
Includes:
Sh
Defined in:
lib/gta/stage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sh

#commander, #sh, #sh!

Constructor Details

#initialize(name, manager, opts) ⇒ Stage

Returns a new instance of Stage.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gta/stage.rb', line 8

def initialize(name, manager, opts)
  @name = name
  @manager = manager
  @repository =   opts['repository']
  @source_name =  opts['source']
  @branch =       opts['branch'] || 'master'
  @tag =          opts['tag']
  @final =        opts['final']
  @hotfixable =   opts['hotfixable']
  @restorable =   opts['restorable']
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



5
6
7
# File 'lib/gta/stage.rb', line 5

def branch
  @branch
end

#finalObject (readonly)

Returns the value of attribute final.



5
6
7
# File 'lib/gta/stage.rb', line 5

def final
  @final
end

#hotfixableObject (readonly)

Returns the value of attribute hotfixable.



5
6
7
# File 'lib/gta/stage.rb', line 5

def hotfixable
  @hotfixable
end

#managerObject (readonly)

Returns the value of attribute manager.



5
6
7
# File 'lib/gta/stage.rb', line 5

def manager
  @manager
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gta/stage.rb', line 5

def name
  @name
end

#repositoryObject (readonly)

Returns the value of attribute repository.



5
6
7
# File 'lib/gta/stage.rb', line 5

def repository
  @repository
end

#restorableObject (readonly)

Returns the value of attribute restorable.



5
6
7
# File 'lib/gta/stage.rb', line 5

def restorable
  @restorable
end

#source_nameObject (readonly)

Returns the value of attribute source_name.



5
6
7
# File 'lib/gta/stage.rb', line 5

def source_name
  @source_name
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/gta/stage.rb', line 5

def tag
  @tag
end

Instance Method Details

#==(other) ⇒ Object



78
79
80
81
82
83
# File 'lib/gta/stage.rb', line 78

def ==(other)
   other.is_a?(self.class) &&
    name == other.name &&
    branch == other.branch &&
    tag == other.tag
end

#add_remoteObject



28
29
30
31
32
33
# File 'lib/gta/stage.rb', line 28

def add_remote
  raise "no name defined for #{self}" unless name
  raise "no repository defined for #{name}" unless repository

  sh("git remote add #{name} #{repository}")
end

#checkoutObject



35
36
37
38
# File 'lib/gta/stage.rb', line 35

def checkout
  delete_existing_branch if existing_branch?
  sh(checkout_command)
end

#checkout!Object



40
41
42
43
# File 'lib/gta/stage.rb', line 40

def checkout!
  delete_existing_branch if existing_branch?
  sh!(checkout_command)
end

#checkout_commandObject



45
46
47
# File 'lib/gta/stage.rb', line 45

def checkout_command
  "git checkout -b #{name} -t #{name}/#{branch}"
end

#delete_existing_branchObject



69
70
71
72
# File 'lib/gta/stage.rb', line 69

def delete_existing_branch
  sh("git checkout master") # in case already on branch
  sh("git branch -D #{name}")
end

#existing_branch?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/gta/stage.rb', line 74

def existing_branch?
  sh('git branch').include?(name)
end

#fetchObject



57
58
59
# File 'lib/gta/stage.rb', line 57

def fetch
  sh(fetch_command)
end

#fetch!Object



61
62
63
# File 'lib/gta/stage.rb', line 61

def fetch!
  sh!(fetch_command)
end

#fetch_commandObject



65
66
67
# File 'lib/gta/stage.rb', line 65

def fetch_command
  "git fetch #{name}"
end

#final?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/gta/stage.rb', line 85

def final?
  !!final
end

#force_push(s = source) ⇒ Object



53
54
55
# File 'lib/gta/stage.rb', line 53

def force_push(s=source)
  sh!(push_command(source_from(s), :force))
end

#hotfixable?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/gta/stage.rb', line 93

def hotfixable?
  !!hotfixable
end

#push(s = source, forced = nil) ⇒ Object



49
50
51
# File 'lib/gta/stage.rb', line 49

def push(s=source, forced=nil)
  sh!(push_command(source_from(s), forced))
end

#push_command(source_ref, forced = nil) ⇒ Object



107
108
109
110
# File 'lib/gta/stage.rb', line 107

def push_command(source_ref, forced=nil)
  force = forced == :force ? " -f" : ""
  "git push#{force} #{name} #{source_ref}:#{branch}"
end

#restorable?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/gta/stage.rb', line 89

def restorable?
  !!restorable
end

#sourceObject



24
25
26
# File 'lib/gta/stage.rb', line 24

def source
  @source ||= manager.stage!(source_name)
end

#source_from(s) ⇒ Object




99
100
101
# File 'lib/gta/stage.rb', line 99

def source_from(s)
  s.respond_to?(:source_ref) ? s.source_ref : s
end

#source_refObject



103
104
105
# File 'lib/gta/stage.rb', line 103

def source_ref
  TagFinder.new(tag).newest || "#{name}"
end

#stagesObject



20
21
22
# File 'lib/gta/stage.rb', line 20

def stages
  manager.stages
end