Class: Flexite::Diff::PushService

Inherits:
Object
  • Object
show all
Defined in:
app/services/flexite/diff/push_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(stage, url) ⇒ PushService

Returns a new instance of PushService.



4
5
6
7
8
# File 'app/services/flexite/diff/push_service.rb', line 4

def initialize(stage, url)
  @stage = stage
  @remote_diff = Diff.new(url)
  @state_digest = Flexite.state_digest
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/flexite/diff/push_service.rb', line 10

def call
  checksum = Flexite.cache.read("#{@state_digest}-#{@stage}-diff-checksum")
  Flexite.cache.delete_matched(Flexite.match_key("-#{@stage}-diff-checksum"))
  Flexite.cache.delete_matched(Flexite.match_key("-#{@stage}-show-diff"))


  if checksum.blank?
    return ActionService::Result.new(flash: { type: :warning, message: 'Settings were changed and difference should be revalidated' })
  end

  response = @remote_diff.apply({ token: Flexite.config.migration_token, stage: Flexite.config.stagename, checksum: checksum })

  if response[:error].blank?
    ActionService::Result.new(flash: { type: :success, message: response[:message] })
  else
    ActionService::Result.new(flash: { type: :danger, message: "#{response[:error]}, code: #{response[:code]}" })
  end
end