Class: MediaScrubber

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/concerns/media_scrubber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MediaScrubber

Returns a new instance of MediaScrubber.



4
5
6
7
# File 'app/controllers/concerns/media_scrubber.rb', line 4

def initialize(args)
  @original = args.fetch(:file, nil)
  @filtered = infer_media_type
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



2
3
4
# File 'app/controllers/concerns/media_scrubber.rb', line 2

def errors
  @errors
end

#filteredObject

Returns the value of attribute filtered.



2
3
4
# File 'app/controllers/concerns/media_scrubber.rb', line 2

def filtered
  @filtered
end

#originalObject

Returns the value of attribute original.



2
3
4
# File 'app/controllers/concerns/media_scrubber.rb', line 2

def original
  @original
end

Instance Method Details

#infer_media_typeObject



9
10
11
12
13
14
# File 'app/controllers/concerns/media_scrubber.rb', line 9

def infer_media_type
  return nil unless original.respond_to?(:content_type)
  params = { file: original }
  return AtomicCms::Image.new(params) if original.content_type =~ /image/
  AtomicCms::Video.new(params) if original.content_type =~ /video/
end

#saveObject



23
24
25
26
# File 'app/controllers/concerns/media_scrubber.rb', line 23

def save
  return false unless valid?
  filtered.save
end

#urlObject



28
29
30
31
# File 'app/controllers/concerns/media_scrubber.rb', line 28

def url
  return nil unless filtered
  filtered.file.url
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'app/controllers/concerns/media_scrubber.rb', line 16

def valid?
  return false unless filtered
  return true if filtered.valid?
  @errors = filtered.errors
  false
end