Class: Reacto::Cache::File

Inherits:
Object
  • Object
show all
Defined in:
lib/reacto/cache/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location: nil, ttl: 60) ⇒ File

Returns a new instance of File.



10
11
12
13
14
15
16
17
18
19
# File 'lib/reacto/cache/file.rb', line 10

def initialize(location: nil, ttl: 60)
  @location = location
  @ttl = ttl

  if @location.nil?
    fail(
      ArgumentError, 'File location is mandatory while using file cache!'
    )
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/reacto/cache/file.rb', line 8

def data
  @data
end

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/reacto/cache/file.rb', line 7

def location
  @location
end

#ttlObject (readonly)

Returns the value of attribute ttl.



7
8
9
# File 'lib/reacto/cache/file.rb', line 7

def ttl
  @ttl
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/reacto/cache/file.rb', line 43

def closed?
  return false unless ready?
  deserialize

  data.closed?
end

#eachObject



27
28
29
30
31
32
33
34
# File 'lib/reacto/cache/file.rb', line 27

def each
  return unless ready?
  deserialize

  data.each do |value|
    yield value
  end
end

#errorObject



50
51
52
53
54
55
# File 'lib/reacto/cache/file.rb', line 50

def error
  return false unless ready?
  deserialize

  data.error
end

#error?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/reacto/cache/file.rb', line 36

def error?
  return false unless ready?
  deserialize

  data.error?
end

#on_closeObject



70
71
72
73
74
75
# File 'lib/reacto/cache/file.rb', line 70

def on_close
  init_data

  data.on_close
  serialize
end

#on_error(error) ⇒ Object



63
64
65
66
67
68
# File 'lib/reacto/cache/file.rb', line 63

def on_error(error)
  init_data

  data.on_error(error)
  serialize
end

#on_value(value) ⇒ Object



57
58
59
60
61
# File 'lib/reacto/cache/file.rb', line 57

def on_value(value)
  init_data

  data.on_value(value)
end

#ready?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/reacto/cache/file.rb', line 21

def ready?
  return data.ready? unless data.nil?

  fresh?
end