Class: JiraSync::LocalIssueRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/jirasync/local_repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LocalIssueRepository

Returns a new instance of LocalIssueRepository.



8
9
10
11
# File 'lib/jirasync/local_repository.rb', line 8

def initialize(path)
    @path = path
    FileUtils::mkdir_p @path
end

Instance Method Details

#load_stateObject



34
35
36
37
38
39
40
41
42
# File 'lib/jirasync/local_repository.rb', line 34

def load_state()
    file_path = "#{@path}/sync_state.json"
    if (!File.exists?(file_path))
        raise ("File '#{file_path}' with previous sync state could not be found\n" +
                  "please run an initial fetch first")
    end
    s = IO.read(file_path)
    JSON.parse(s)
end

#save(issue) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/jirasync/local_repository.rb', line 13

def save(issue)
    json = JSON.pretty_generate(issue)
    file_path = "#{@path}/#{issue['key']}.json"
    File.write(file_path, json)

    updateTime = DateTime.parse(issue['fields']['updated'])

    File.utime(DateTime.now.to_time, updateTime.to_time, file_path)
end

#save_attachment(issue, attachment, data) ⇒ Object



44
45
46
47
48
# File 'lib/jirasync/local_repository.rb', line 44

def save_attachment(issue, attachment, data)
    FileUtils::mkdir_p("#{@path}/attachments")
    file_path = "#{@path}/attachments/#{issue['key']}-#{attachment['id']}-#{attachment['filename'].gsub(" ", "_")}"
    File.write(file_path, data, {:mode => 'wb'})
end

#save_state(state) ⇒ Object



28
29
30
31
32
# File 'lib/jirasync/local_repository.rb', line 28

def save_state(state)
    json = JSON.pretty_generate(state)
    file_path = "#{@path}/sync_state.json"
    File.write(file_path, json)
end

#state_exists?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/jirasync/local_repository.rb', line 23

def state_exists?
    file_path = "#{@path}/sync_state.json"
    File.exist?(file_path)
end