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

Returns a new instance of EncodingConfirmation.



8
9
10
11
12
13
14
# 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
  @account = entry.
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



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

def 
  @account
end

#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



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

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

#exceeding?Boolean

Returns:

  • (Boolean)


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

def exceeding?
  assumed_quota.exceeded?
end

#filesObject



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

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

#save!Object



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

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

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