Class: Txgh::ResourceUpdater

Inherits:
Object
  • Object
show all
Includes:
CategorySupport
Defined in:
lib/txgh/resource_updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CategorySupport

#deserialize_categories, #escape_category, #join_categories, #serialize_categories

Constructor Details

#initialize(project, repo, logger = nil) ⇒ ResourceUpdater

Returns a new instance of ResourceUpdater.



9
10
11
12
13
# File 'lib/txgh/resource_updater.rb', line 9

def initialize(project, repo, logger = nil)
  @project = project
  @repo = repo
  @logger = logger || Logger.new(STDOUT)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/txgh/resource_updater.rb', line 7

def logger
  @logger
end

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'lib/txgh/resource_updater.rb', line 7

def project
  @project
end

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/txgh/resource_updater.rb', line 7

def repo
  @repo
end

Instance Method Details

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/txgh/resource_updater.rb', line 15

def update_resource(tx_resource, categories = {})
  # don't process the resource unless the project slugs are the same
  return unless tx_resource.project_slug == project.name
  branch = tx_resource.branch || repo.diff_point
  file = repo.api.download(tx_resource.source_file, branch)

  if repo.upload_diffs? && tx_resource.has_branch?
    upload_diff(tx_resource, file, categories)
  else
    upload_whole(tx_resource, file, categories)
  end

  Txgh.events.publish(
    'transifex.resource.updated', {
      project: project, repo: repo, resource: tx_resource,
      branch: tx_resource.branch
    }
  )
end