Class: KMDB::JsonFile

Inherits:
Object
  • Object
show all
Defined in:
lib/kmdb/models/json_file.rb

Overview

Models one of KissMetrics’s JSON dumps. Supports caching them from S3 and finding the latest one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision) ⇒ JsonFile

Returns a new instance of JsonFile.



11
12
13
# File 'lib/kmdb/models/json_file.rb', line 11

def initialize(revision)
  @revision = revision
end

Instance Attribute Details

#revisionObject (readonly)

Returns the value of attribute revision.



9
10
11
# File 'lib/kmdb/models/json_file.rb', line 9

def revision
  @revision
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/kmdb/models/json_file.rb', line 24

def exist?
  _cached_path.exist? || _s3object.exist?
end

#metadataObject



28
29
30
# File 'lib/kmdb/models/json_file.rb', line 28

def 
  @metadata ||= Dumpfile.get(revision)
end

#open(&block) ⇒ Object

Yields an IO object for this file



16
17
18
19
20
21
22
# File 'lib/kmdb/models/json_file.rb', line 16

def open(&block)
  _cached.open('r') do |io|
    .update_attributes!(length: io.size)
    yield io
  end
  _flush_cache if _should_flush?
end