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, commit_sha, categories = {}) ⇒ Object

For each modified resource, get its content and update the content in Transifex.



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

def update_resource(tx_resource, commit_sha, categories = {})
  # don't process the resource unless the project slugs are the same
  return unless tx_resource.project_slug == project.name

  logger.info('process updated resource')
  tree_sha = repo.api.get_commit(repo.name, commit_sha)['commit']['tree']['sha']
  tree = repo.api.tree(repo.name, tree_sha)

  tree['tree'].each do |file|
    logger.info("process each tree entry: #{file['path']}")

    if tx_resource.source_file == file['path']
      if repo.upload_diffs?
        upload_diff(tx_resource, file, categories)
      else
        upload_whole(tx_resource, file, categories)
      end
    end
  end
end