Class: Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Asset
- Defined in:
- app/models/asset.rb
Class Method Summary collapse
- .count_with_asset_types(asset_types, *args) ⇒ Object
-
.find_all_by_asset_types(asset_types, *args) ⇒ Object
searching and pagination moved to the controller.
- .known_types ⇒ Object
- .with_asset_types(asset_types, &block) ⇒ Object
Instance Method Summary collapse
- #aspect(style_name = 'original') ⇒ Object
- #asset_type ⇒ Object
- #attached_to?(page) ⇒ Boolean
- #basename ⇒ Object
- #dimensions_known? ⇒ Boolean
- #extension(style_name = 'original') ⇒ Object
- #geometry(style_name = 'original') ⇒ Object
- #has_style?(style_name = 'original') ⇒ Boolean
- #height(style_name = 'original') ⇒ Object
- #horizontal?(style_name = 'original') ⇒ Boolean
- #orientation(style_name = 'original') ⇒ Object
- #original_extension ⇒ Object
- #original_geometry ⇒ Object
- #square?(style_name = 'original') ⇒ Boolean
- #thumbnail(style_name = 'original') ⇒ Object
- #vertical?(style_name = 'original') ⇒ Boolean
- #width(style_name = 'original') ⇒ Object
Class Method Details
.count_with_asset_types(asset_types, *args) ⇒ Object
197 198 199 |
# File 'app/models/asset.rb', line 197 def count_with_asset_types(asset_types, *args) with_asset_types(asset_types) { count *args } end |
.find_all_by_asset_types(asset_types, *args) ⇒ Object
searching and pagination moved to the controller
193 194 195 |
# File 'app/models/asset.rb', line 193 def find_all_by_asset_types(asset_types, *args) with_asset_types(asset_types) { find *args } end |
.known_types ⇒ Object
187 188 189 |
# File 'app/models/asset.rb', line 187 def known_types AssetType.known_types end |
.with_asset_types(asset_types, &block) ⇒ Object
201 202 203 |
# File 'app/models/asset.rb', line 201 def with_asset_types(asset_types, &block) with_scope(:find => { :conditions => AssetType.conditions_for(asset_types) }, &block) end |
Instance Method Details
#aspect(style_name = 'original') ⇒ Object
118 119 120 |
# File 'app/models/asset.rb', line 118 def aspect(style_name='original') geometry(style_name).aspect end |
#asset_type ⇒ Object
61 62 63 |
# File 'app/models/asset.rb', line 61 def asset_type AssetType.for(asset) end |
#attached_to?(page) ⇒ Boolean
94 95 96 |
# File 'app/models/asset.rb', line 94 def attached_to?(page) pages.include?(page) end |
#basename ⇒ Object
76 77 78 |
# File 'app/models/asset.rb', line 76 def basename File.basename(asset_file_name, ".*") if asset_file_name end |
#dimensions_known? ⇒ Boolean
156 157 158 |
# File 'app/models/asset.rb', line 156 def dimensions_known? original_width? && original_height? end |
#extension(style_name = 'original') ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'app/models/asset.rb', line 80 def extension(style_name='original') if style_name == 'original' return original_extension elsif style = paperclip_styles[style_name.to_sym] return style.format else return original_extension end end |
#geometry(style_name = 'original') ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/asset.rb', line 102 def geometry(style_name='original') raise Paperclip::StyleError, "Requested style #{style_name} is not defined for this asset." unless has_style?(style_name) @geometry ||= {} begin @geometry[style_name] ||= if style_name.to_s == 'original' original_geometry else style = self.asset.styles[style_name.to_sym] original_geometry.transformed_by(style.geometry) # this can return dimensions for fully specified style sizes but not for relative sizes when there are no original dimensions end rescue Paperclip::TransformationError => e Rails.logger.warn "geometry transformation error: #{e}" original_geometry # returns a blank geometry if the real geometry cannot be calculated end end |
#has_style?(style_name = 'original') ⇒ Boolean
72 73 74 |
# File 'app/models/asset.rb', line 72 def has_style?(style_name='original') style_name == 'original' || paperclip_styles.keys.include?(style_name.to_sym) end |
#height(style_name = 'original') ⇒ Object
140 141 142 |
# File 'app/models/asset.rb', line 140 def height(style_name='original') geometry(style_name).height.to_i end |
#horizontal?(style_name = 'original') ⇒ Boolean
152 153 154 |
# File 'app/models/asset.rb', line 152 def horizontal?(style_name='original') geometry(style_name).horizontal? end |
#orientation(style_name = 'original') ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/asset.rb', line 122 def orientation(style_name='original') a = aspect(style_name) case when a == nil? 'unknown' when a < 1.0 'vertical' when a > 1.0 'horizontal' else 'square' end end |
#original_extension ⇒ Object
90 91 92 |
# File 'app/models/asset.rb', line 90 def original_extension return asset_file_name.split('.').last.downcase if asset_file_name end |
#original_geometry ⇒ Object
98 99 100 |
# File 'app/models/asset.rb', line 98 def original_geometry @original_geometry ||= Paperclip::Geometry.new(original_width, original_height) end |
#square?(style_name = 'original') ⇒ Boolean
144 145 146 |
# File 'app/models/asset.rb', line 144 def square?(style_name='original') geometry(style_name).square? end |
#thumbnail(style_name = 'original') ⇒ Object
66 67 68 69 70 |
# File 'app/models/asset.rb', line 66 def thumbnail(style_name='original') return asset.url if style_name.to_sym == :original return asset.url(style_name.to_sym) if has_style?(style_name) return asset_type.icon(style_name) end |
#vertical?(style_name = 'original') ⇒ Boolean
148 149 150 |
# File 'app/models/asset.rb', line 148 def vertical?(style_name='original') geometry(style_name).vertical? end |
#width(style_name = 'original') ⇒ Object
136 137 138 |
# File 'app/models/asset.rb', line 136 def width(style_name='original') geometry(style_name).width.to_i end |