Class: JiraSync::LocalIssueRepository
- Inherits:
-
Object
- Object
- JiraSync::LocalIssueRepository
- Defined in:
- lib/jirasync/local_repository.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ LocalIssueRepository
constructor
A new instance of LocalIssueRepository.
- #load_state ⇒ Object
- #save(issue) ⇒ Object
- #save_attachment(issue, attachment, data) ⇒ Object
- #save_state(state) ⇒ Object
- #state_exists? ⇒ Boolean
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_state ⇒ Object
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 (issue, , data) FileUtils::mkdir_p("#{@path}/attachments") file_path = "#{@path}/attachments/#{issue['key']}-#{['id']}-#{['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
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 |