Class: WikiAvro::Avro::RevisionWriter

Inherits:
AvroWriter
  • Object
show all
Defined in:
lib/wikiavro/avro.rb

Instance Method Summary collapse

Methods inherited from AvroWriter

#close

Instance Method Details

#schemaObject



139
140
141
# File 'lib/wikiavro/avro.rb', line 139

def schema
  REVISION_SCHEMA
end

#write(id, page_id, n, timestamp, contributor, minor, comment, text_deleted, bytes, textid, text) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/wikiavro/avro.rb', line 143

def write(id, page_id, n, timestamp, contributor, minor,
          comment, text_deleted, bytes, textid, text)
  if !contributor[:deleted].nil? && !(contributor[:id].nil? &&
                                      contributor[:username].nil? &&
                                      contributor[:ip].nil?)
    raise 'deleted contributor has content'
  end

  if contributor[:deleted].nil?
    contributor.delete :deleted
    contributor = {
      'username' => contributor[:username],
      'id' => contributor[:id].to_i,
      'ip' => contributor[:ip]
    }
  else
    contributor = nil
  end

  if !comment.nil?
    if !(comment[:deleted].nil? ^ comment[:comment].nil?)
      raise 'comment[:deleted] and comment[:comment] should alternate'
    end

    if comment[:deleted].nil?
      comment[:comment]
    else
      comment.delete :deleted
      comment[:comment] = nil
    end
  end

  text = nil if !text_deleted.nil?

  encode 'id' => id.to_i,
         'page_id' => page_id.to_i,
         'n' => n.to_i,
         'timestamp' => timestamp,
         'contributor' => contributor,
         'minor' => !!minor,
         'comment' => comment,
         'bytes' => bytes.to_i,
         'textid' => textid,
         'text' => text
end