Class: Txgh::Pusher

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh/pusher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, repo, branch = nil) ⇒ Pusher

Returns a new instance of Pusher.



5
6
7
8
9
# File 'lib/txgh/pusher.rb', line 5

def initialize(project, repo, branch = nil)
  @project = project
  @repo = repo
  @branch = branch
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



3
4
5
# File 'lib/txgh/pusher.rb', line 3

def branch
  @branch
end

#projectObject (readonly)

Returns the value of attribute project.



3
4
5
# File 'lib/txgh/pusher.rb', line 3

def project
  @project
end

#repoObject (readonly)

Returns the value of attribute repo.



3
4
5
# File 'lib/txgh/pusher.rb', line 3

def repo
  @repo
end

Instance Method Details

#push(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/txgh/pusher.rb', line 11

def push(&block)
  existing_resources = project.api.get_resources(project.name)
  slugs = existing_resources.map { |resource| resource['slug'] }

  resources = tx_config.resources.each_with_object([]) do |tx_resource, ret|
    if repo.process_all_branches?
      tx_resource = Txgh::TxBranchResource.new(tx_resource, branch)
    end

    next unless slugs.include?(tx_resource.resource_slug)
    ret << tx_resource
  end

  push_resources(resources, &block)
end

#push_resource(tx_resource, categories = {}) ⇒ Object



34
35
36
# File 'lib/txgh/pusher.rb', line 34

def push_resource(tx_resource, categories = {})
  updater.update_resource(tx_resource, categories)
end

#push_resources(tx_resources, &block) ⇒ Object



27
28
29
30
31
32
# File 'lib/txgh/pusher.rb', line 27

def push_resources(tx_resources, &block)
  tx_resources.each do |tx_resource|
    categories = block_given? ? yield(tx_resource) : {}
    push_resource(tx_resource, categories)
  end
end

#push_slug(resource_slug, categories = {}) ⇒ Object



38
39
40
# File 'lib/txgh/pusher.rb', line 38

def push_slug(resource_slug, categories = {})
  push_resource(tx_config.resource(resource_slug, branch), categories)
end