Class: MediaScrubber
- Inherits:
-
Object
- Object
- MediaScrubber
- Defined in:
- app/controllers/concerns/media_scrubber.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#filtered ⇒ Object
Returns the value of attribute filtered.
-
#original ⇒ Object
Returns the value of attribute original.
Instance Method Summary collapse
- #infer_media_type ⇒ Object
-
#initialize(args) ⇒ MediaScrubber
constructor
A new instance of MediaScrubber.
- #save ⇒ Object
- #url ⇒ Object
- #valid? ⇒ Boolean
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
#errors ⇒ Object
Returns the value of attribute errors.
2 3 4 |
# File 'app/controllers/concerns/media_scrubber.rb', line 2 def errors @errors end |
#filtered ⇒ Object
Returns the value of attribute filtered.
2 3 4 |
# File 'app/controllers/concerns/media_scrubber.rb', line 2 def filtered @filtered end |
#original ⇒ Object
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_type ⇒ Object
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 |
#save ⇒ Object
23 24 25 26 |
# File 'app/controllers/concerns/media_scrubber.rb', line 23 def save return false unless valid? filtered.save end |
#url ⇒ Object
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
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 |