Class: Pageflow::EncodingConfirmation

Inherits:
Object
  • Object
show all
Defined in:
app/models/pageflow/encoding_confirmation.rb

Defined Under Namespace

Classes: QuotaExceededError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, attributes, encoding_quota, user) ⇒ EncodingConfirmation


8
9
10
11
12
13
# File 'app/models/pageflow/encoding_confirmation.rb', line 8

def initialize(entry, attributes, encoding_quota, user)
  @entry = entry
  @attributes = attributes
  @encoding_quota = encoding_quota
  @user = user
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes


6
7
8
# File 'app/models/pageflow/encoding_confirmation.rb', line 6

def attributes
  @attributes
end

#encoding_quotaObject (readonly)

Returns the value of attribute encoding_quota


6
7
8
# File 'app/models/pageflow/encoding_confirmation.rb', line 6

def encoding_quota
  @encoding_quota
end

#entryObject (readonly)

Returns the value of attribute entry


6
7
8
# File 'app/models/pageflow/encoding_confirmation.rb', line 6

def entry
  @entry
end

#userObject (readonly)

Returns the value of attribute user


6
7
8
# File 'app/models/pageflow/encoding_confirmation.rb', line 6

def user
  @user
end

Instance Method Details

#assumed_quotaObject


30
31
32
# File 'app/models/pageflow/encoding_confirmation.rb', line 30

def assumed_quota
  @assumed_quota ||= encoding_quota.assume(files: files)
end

#exceeding?Boolean


15
16
17
# File 'app/models/pageflow/encoding_confirmation.rb', line 15

def exceeding?
  assumed_quota.exceeded?
end

#filesObject


34
35
36
37
38
# File 'app/models/pageflow/encoding_confirmation.rb', line 34

def files
  @files ||=
    entry.video_files.find(attributes.fetch(:video_file_ids, [])) +
    entry.audio_files.find(attributes.fetch(:audio_file_ids, []))
end

#save!Object


19
20
21
22
23
24
25
26
27
28
# File 'app/models/pageflow/encoding_confirmation.rb', line 19

def save!
  ActiveRecord::Base.transaction do
    raise(QuotaExceededError) if exceeding?

    files.each do |file|
      file.confirmed_by = user
      file.confirm_encoding!
    end
  end
end