Sha256: 18d670fd00c7dd21b90fb7bbce4a19776533f9abc64a69c139c8b7e205375b61

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

module JiraSync
    require 'fileutils'
    require 'json'


    class LocalIssueRepository

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

        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

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

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

        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
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jirasync-0.4.3 lib/jirasync/local_repository.rb
jirasync-0.4.2 lib/jirasync/local_repository.rb
jirasync-0.4.1 lib/jirasync/local_repository.rb
jirasync-0.4.0 lib/jirasync/local_repository.rb
jirasync-0.3 lib/jirasync/local_repository.rb