Class: AssetCloud::AssetExtension
- Inherits:
-
Object
- Object
- AssetCloud::AssetExtension
- Includes:
- Callbacks, Validations
- Defined in:
- lib/asset_cloud/asset_extension.rb
Defined Under Namespace
Classes: AssetMismatch
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(asset) ⇒ AssetExtension
constructor
A new instance of AssetExtension.
- #store ⇒ Object
Methods included from Validations
#add_error, #add_warning, #errors, included, #valid?, #validate, #warnings
Methods included from Callbacks
#callbacks_for, #execute_callback, #execute_callbacks
Constructor Details
#initialize(asset) ⇒ AssetExtension
Returns a new instance of AssetExtension.
46 47 48 49 50 51 52 |
# File 'lib/asset_cloud/asset_extension.rb', line 46 def initialize(asset) unless self.class.applies_to_asset?(asset) raise AssetMismatch, "Instances of #{self.class.name} cannot be applied to asset #{asset.key.inspect}" end @asset = asset end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
21 22 23 |
# File 'lib/asset_cloud/asset_extension.rb', line 21 def asset @asset end |
Class Method Details
.applies_to(*args) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/asset_cloud/asset_extension.rb', line 28 def applies_to(*args) extnames = args.map do |arg| arg = arg.to_s.downcase arg = ".#{arg}" unless arg.starts_with?(".") arg end self.extnames = extnames end |
.applies_to_asset?(asset) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/asset_cloud/asset_extension.rb', line 37 def applies_to_asset?(asset) extnames = self.extnames || [] extnames.each do |extname| return true if asset.key.downcase.ends_with?(extname) end false end |
Instance Method Details
#delete ⇒ Object
12 13 14 |
# File 'lib/asset_cloud/asset_extension.rb', line 12 def delete true end |
#store ⇒ Object
8 9 10 |
# File 'lib/asset_cloud/asset_extension.rb', line 8 def store true end |