Module: Fera::HasMedia
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer, Product, Review, Submission
- Defined in:
- lib/fera/models/concerns/has_media.rb
Instance Method Summary collapse
- #add_media(input) ⇒ Object
- #add_photo(input) ⇒ Object
- #add_video(input) ⇒ Object
- #media(query = {}) ⇒ Object
- #media=(inputs) ⇒ Object
- #new_media(input = nil) ⇒ Object
- #new_photo(input = nil) ⇒ Object
- #new_video(input = nil) ⇒ Object
- #photos(query = {}) ⇒ Object
- #photos=(inputs) ⇒ Object
- #videos(query = {}) ⇒ Object
- #videos=(inputs) ⇒ Object
Instance Method Details
#add_media(input) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/fera/models/concerns/has_media.rb', line 19 def add_media(input) new_model = self.new_media(input) if @media.nil? @media = [new_model] else @media << new_model end end |
#add_photo(input) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/fera/models/concerns/has_media.rb', line 47 def add_photo(input) new_model = self.new_photo(input) if @photos.nil? @photos = [new_model] else @photos << new_model end end |
#add_video(input) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/fera/models/concerns/has_media.rb', line 74 def add_video(input) new_model = self.new_video(input) if @videos.nil? @videos = [new_model] else @videos << new_model end end |
#media(query = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/fera/models/concerns/has_media.rb', line 33 def media(query = {}) if @media && query.blank? @media.to_a else Media.where(query.merge("#{ self.class.name.demodulize.underscore }_id" => id)) end end |
#media=(inputs) ⇒ Object
13 14 15 16 17 |
# File 'lib/fera/models/concerns/has_media.rb', line 13 def media=(inputs) @media = inputs.to_a.map do |input| self.new_media(input) end end |
#new_media(input = nil) ⇒ Object
28 29 30 31 |
# File 'lib/fera/models/concerns/has_media.rb', line 28 def new_media(input = nil) model_class = [Photo, Video].include?(input.class) ? input.class : Media new_has_many_associated_model(model_class, input) end |
#new_photo(input = nil) ⇒ Object
56 57 58 |
# File 'lib/fera/models/concerns/has_media.rb', line 56 def new_photo(input = nil) new_has_many_associated_model(Photo, input) end |
#new_video(input = nil) ⇒ Object
83 84 85 |
# File 'lib/fera/models/concerns/has_media.rb', line 83 def new_video(input = nil) new_has_many_associated_model(Video, input) end |
#photos(query = {}) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/fera/models/concerns/has_media.rb', line 60 def photos(query = {}) if @photos && query.blank? @photos.to_a else Photo.where(query.merge("#{ self.class.name.demodulize.underscore }_id" => id)) end end |
#photos=(inputs) ⇒ Object
41 42 43 44 45 |
# File 'lib/fera/models/concerns/has_media.rb', line 41 def photos=(inputs) @photos = inputs.to_a.map do |input| new_has_many_associated_model(Photo, input) end end |
#videos(query = {}) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/fera/models/concerns/has_media.rb', line 87 def videos(query = {}) if @videos && query.blank? @videos.to_a else Video.where(query.merge("#{ self.class.name.demodulize.underscore }_id" => id)) end end |
#videos=(inputs) ⇒ Object
68 69 70 71 72 |
# File 'lib/fera/models/concerns/has_media.rb', line 68 def videos=(inputs) @videos = inputs.to_a.map do |input| self.new_video(input) end end |