Class: Nsync::Consumer::Change

Inherits:
Struct
  • Object
show all
Defined in:
lib/nsync/consumer.rb

Direct Known Subclasses

Producer::Change

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#diffObject

Returns the value of attribute diff

Returns:

  • (Object)

    the current value of diff



154
155
156
# File 'lib/nsync/consumer.rb', line 154

def diff
  @diff
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



154
155
156
# File 'lib/nsync/consumer.rb', line 154

def id
  @id
end

Instance Method Details

#a_data(parse_json = true) ⇒ Object



171
172
173
174
# File 'lib/nsync/consumer.rb', line 171

def a_data(parse_json=true)
  val = diff.a_blob ? diff.a_blob.data : ""
  parse_json ? json_data(val) : val
end

#b_data(parse_json = true) ⇒ Object



176
177
178
179
# File 'lib/nsync/consumer.rb', line 176

def b_data(parse_json=true)
  val = diff.b_blob ? diff.b_blob.data : ""
  parse_json ? json_data(val) : val
end

#dataObject



181
182
183
# File 'lib/nsync/consumer.rb', line 181

def data
  @data ||= b_data
end

#json_data(data) ⇒ Object



155
156
157
158
159
# File 'lib/nsync/consumer.rb', line 155

def json_data(data)
  JSON.load(data)
rescue
  {}
end

#typeObject



161
162
163
164
165
166
167
168
169
# File 'lib/nsync/consumer.rb', line 161

def type
  if diff.deleted_file
    :deleted
  elsif diff.new_file
    :added
  else
    :modified
  end
end