Module: Binda::FieldableAssociationHelpers::FieldableVideoHelpers
- Included in:
- Binda::FieldableAssociationHelpers
- Defined in:
- app/models/concerns/binda/fieldable_association_helpers/fieldable_video_helpers.rb
Instance Method Summary collapse
-
#get_video_info(field_slug, info) ⇒ string, boolean
Get the object related to that field setting.
-
#get_video_path(field_slug) ⇒ string
Get the video path based on the size provided, default is Carrierwave default (usually the real size).
-
#get_video_url(field_slug) ⇒ string
Get the video url based on the size provided, default is Carrierwave default (usually the real size).
-
#has_video(field_slug) ⇒ boolean
Check if the field has an attached video.
Instance Method Details
#get_video_info(field_slug, info) ⇒ string, boolean
Get the object related to that field setting
41 42 43 44 45 46 47 48 49 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_video_helpers.rb', line 41 def get_video_info(field_slug, info) obj = self.videos.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) } # Alternative query # obj = video.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first raise ArgumentError, "There isn't any video associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil? if obj.video.present? obj.video.send(info) end end |
#get_video_path(field_slug) ⇒ string
Get the video path based on the size provided,
default is Carrierwave default (usually the real size)
31 32 33 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_video_helpers.rb', line 31 def get_video_path(field_slug) get_video_info( field_slug, 'path' ) end |
#get_video_url(field_slug) ⇒ string
Get the video url based on the size provided,
default is Carrierwave default (usually the real size)
22 23 24 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_video_helpers.rb', line 22 def get_video_url(field_slug) get_video_info( field_slug, 'url' ) end |
#has_video(field_slug) ⇒ boolean
Check if the field has an attached video
9 10 11 12 13 14 15 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_video_helpers.rb', line 9 def has_video(field_slug) obj = self.videos.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) } # Alternative query # obj = Image.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first raise ArgumentError, "There isn't any video associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil? return obj.video.present? end |