Class: VimeoEmbedCache
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- VimeoEmbedCache
- Defined in:
- app/models/vimeo_embed_cache.rb
Constant Summary collapse
- FIXED_WIDTH_GEOMETRY =
e.g. ‘300’
/^(\d+)$/
- FIXED_HEIGHT_GEOMETRY =
e.g. ‘x200’
/^x(\d+)$/
- FIXED_GEOMETRY =
e.g. ‘300x200’
/^(\d+)x(\d+)$/
- VIMEO_GEOMETRY =
Regexp.union FIXED_GEOMETRY, FIXED_HEIGHT_GEOMETRY, FIXED_WIDTH_GEOMETRY
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.embed(vid, geometry, configuration = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/vimeo_embed_cache.rb', line 16 def self. vid, geometry, configuration = {} configuration.stringify_keys! configuration.merge!(geometry_hash(geometry)) static = configuration.delete("static") if configuration.has_key?("static") if static geometry =~ FIXED_GEOMETRY ? (vid, geometry).html_safe : raise(ArgumentError, "Must use fixed geometry string for static embeds (e.g. 100x240)") else find_or_create_by_vid_and_configuration(vid, :configuration => YAML.dump(configuration)).code.html_safe end end |
.geometry_hash(geometry) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/vimeo_embed_cache.rb', line 39 def self.geometry_hash geometry case geometry when FIXED_WIDTH_GEOMETRY {:width => $1} when FIXED_HEIGHT_GEOMETRY {:height => $1} when FIXED_GEOMETRY {:width => $1, :height => $2} else raise ArgumentError, "Didn't recognise the geometry string #{geometry}" end end |
Instance Method Details
#update_cache ⇒ Object
29 30 31 32 |
# File 'app/models/vimeo_embed_cache.rb', line 29 def update_cache cache true self.save end |