Class: RemotePartial::Builder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Builder

Returns a new instance of Builder.



11
12
13
# File 'lib/remote_partial/builder.rb', line 11

def initialize(args)
  @args = Partial.string_keys(args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/remote_partial/builder.rb', line 4

def args
  @args
end

#changedObject (readonly)

Returns the value of attribute changed.



4
5
6
# File 'lib/remote_partial/builder.rb', line 4

def changed
  @changed
end

#partialObject (readonly)

Returns the value of attribute partial.



4
5
6
# File 'lib/remote_partial/builder.rb', line 4

def partial
  @partial
end

Class Method Details

.build(args) ⇒ Object



6
7
8
9
# File 'lib/remote_partial/builder.rb', line 6

def self.build(args)
  builder = new(args)
  builder.run
end

Instance Method Details

#create_or_update_partialObject



22
23
24
25
26
27
28
29
30
31
32
# 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

#runObject



15
16
17
18
19
20
# 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