Class: RemotePartial::Partial

Inherits:
YamlStore
  • Object
show all
Defined in:
lib/remote_partial/partial.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from YamlStore

all, count, dir, file, find, merge!, read, root, #save, string_keys, #time_stamps, write

Instance Attribute Details

#repeat_periodObject

Returns the value of attribute repeat_period.



5
6
7
# File 'lib/remote_partial/partial.rb', line 5

def repeat_period
  @repeat_period
end

#stale_atObject

Returns the value of attribute stale_at.



5
6
7
# File 'lib/remote_partial/partial.rb', line 5

def stale_at
  @stale_at
end

Class Method Details

.create(hash) ⇒ Object



7
8
9
10
# File 'lib/remote_partial/partial.rb', line 7

def self.create(hash)
  super

end

Instance Method Details

#criteriaObject



25
26
27
# File 'lib/remote_partial/partial.rb', line 25

def criteria
  super if present?(super)
end

#default_repeat_periodObject



37
38
39
# File 'lib/remote_partial/partial.rb', line 37

def default_repeat_period
  TimeCalc.minutes(1)
end

#output_file_nameObject



12
13
14
# File 'lib/remote_partial/partial.rb', line 12

def output_file_name
  [partial_folder, file_name].join("/")
end

#reset_stale_atObject



45
46
47
48
# File 'lib/remote_partial/partial.rb', line 45

def reset_stale_at
  self.stale_at = (Time.now + repeat_period)
  save
end

#resource_managerObject



29
30
31
# File 'lib/remote_partial/partial.rb', line 29

def resource_manager
  ResourceManager.new(url, criteria, &output_modifier_to_lambda)
end

#stale?Boolean



54
55
56
# File 'lib/remote_partial/partial.rb', line 54

def stale?
  stale_at_blank? or stale_at < Time.now
end

#to_hashObject



58
59
60
# File 'lib/remote_partial/partial.rb', line 58

def to_hash
  super.merge('stale_at' => stale_at)
end

#update_fileObject



16
17
18
19
# File 'lib/remote_partial/partial.rb', line 16

def update_file
  resource_manager.output_to(output_file_name)
  update_stale_at
end

#update_stale_atObject



41
42
43
# File 'lib/remote_partial/partial.rb', line 41

def update_stale_at
  reset_stale_at if stale?
end

#update_stale_fileObject



21
22
23
# File 'lib/remote_partial/partial.rb', line 21

def update_stale_file
  update_file if stale?
end