class RemotePartial::Partial

Attributes

repeat_period[RW]
stale_at[RW]

Public Instance Methods

criteria() click to toggle source
Calls superclass method
# File lib/remote_partial/partial.rb, line 20
def criteria
  super if present?(super)
end
default_repeat_period() click to toggle source
# File lib/remote_partial/partial.rb, line 32
def default_repeat_period
  TimeCalc.minutes(1)
end
output_file_name() click to toggle source
# File lib/remote_partial/partial.rb, line 7
def output_file_name
  [partial_folder, file_name].join("/")
end
reset_stale_at() click to toggle source
# File lib/remote_partial/partial.rb, line 40
def reset_stale_at
  self.stale_at = (Time.now + repeat_period)
  save
end
resource_manager() click to toggle source
# File lib/remote_partial/partial.rb, line 24
def resource_manager
  ResourceManager.new(url, criteria, &output_modifier_to_lambda)
end
stale?() click to toggle source
# File lib/remote_partial/partial.rb, line 49
def stale?
  stale_at_blank? or stale_at < Time.now
end
to_hash() click to toggle source
Calls superclass method
# File lib/remote_partial/partial.rb, line 53
def to_hash
  super.merge('stale_at' => stale_at)
end
update_file() click to toggle source
# File lib/remote_partial/partial.rb, line 11
def update_file
  resource_manager.output_to(output_file_name)
  update_stale_at
end
update_stale_at() click to toggle source
# File lib/remote_partial/partial.rb, line 36
def update_stale_at
  reset_stale_at if stale?
end
update_stale_file() click to toggle source
# File lib/remote_partial/partial.rb, line 16
def update_stale_file
  update_file if stale?
end

Private Instance Methods

determine_repeat_period() click to toggle source
# File lib/remote_partial/partial.rb, line 83
def determine_repeat_period
  self[:repeat_period] || self['repeat_period'] || default_repeat_period
end
empty_string_pattern() click to toggle source
# File lib/remote_partial/partial.rb, line 79
def empty_string_pattern
  /\A\s*\Z/
end
file_name() click to toggle source
# File lib/remote_partial/partial.rb, line 62
def file_name
  "_#{name}.html.erb"
end
output_modifier_to_lambda() click to toggle source
# File lib/remote_partial/partial.rb, line 66
def output_modifier_to_lambda
  output_modifier? ? instance_eval("lambda #{output_modifier}") : nil
end
partial_folder() click to toggle source
# File lib/remote_partial/partial.rb, line 58
def partial_folder
  RemotePartial.partial_location
end
present?(item) click to toggle source
# File lib/remote_partial/partial.rb, line 75
def present?(item)
  item and item.to_s !~ empty_string_pattern
end
stale_at_blank?() click to toggle source
# File lib/remote_partial/partial.rb, line 70
def stale_at_blank?
  return true unless stale_at
  !stale_at.kind_of? Time
end