Sha256: da63194c99a781fcc7f3c2343ae2d882a8f87e30155e4938ae7fc970ee6ef152
Contents?: true
Size: 916 Bytes
Versions: 24
Compression:
Stored size: 916 Bytes
Contents
require 'yaml' module Localeapp SyncFile = Struct.new(:path) do def refresh @data = if File.exist?(path) SyncData.from_hash( Localeapp.load_yaml_file(path) ) else SyncData.default end end def write(polled_at, updated_at) data.polled_at = polled_at data.updated_at = updated_at File.open(path, 'w+') { |f| f.write(data.to_yaml) } end def data @data ||= SyncData.default end end SyncData = Struct.new(:polled_at, :updated_at) do def self.default new(0, 0) end def self.from_hash(hash) return default unless hash.is_a?(Hash) new( hash['polled_at'] || hash[:polled_at], hash['updated_at'] || hash[:updated_at] ) end def to_hash {'polled_at' => polled_at.to_i, 'updated_at' => updated_at.to_i} end def to_yaml to_hash.to_yaml end end end
Version data entries
24 entries across 24 versions & 1 rubygems