class RemotePartial::Builder

Attributes

args[R]
changed[R]
partial[R]

Public Class Methods

build(args) click to toggle source
# File lib/remote_partial/builder.rb, line 6
def self.build(args)
  builder = new(args)
  builder.run
end
new(args) click to toggle source
# File lib/remote_partial/builder.rb, line 11
def initialize(args)
  @args = Partial.string_keys(args)
end

Public Instance Methods

create_or_update_partial() click to toggle source
# File lib/remote_partial/builder.rb, line 22
def create_or_update_partial
  @partial = Partial.find(args['name']) || Partial.new(name: args['name'])
  track_change(args, 'url')
  track_change(args, 'output_modifier')
  track_change(args, 'criteria')
  track_change(args, 'repeat_period', @partial.default_repeat_period)

  if changed
    @partial.save
  end
end
run() click to toggle source
# File lib/remote_partial/builder.rb, line 15
def run
  create_or_update_partial
  partial.update_stale_file
rescue RemotePartialRetrivalError => error
  RemotePartial.logger.warn error.message
end

Private Instance Methods

track_change(args, attribute, default = nil) click to toggle source
# File lib/remote_partial/builder.rb, line 35
def track_change(args, attribute, default = nil)
  unless @partial.send(attribute) == args[attribute] or (default and @partial.send(attribute) == default)
    @partial.send("#{attribute}=".to_sym, args.fetch(attribute, default))
    @changed = true
  end
end