Class: Avatar::Source::Wrapper::RailsAssetSourceWrapper
- Inherits:
-
AbstractSourceWrapper
- Object
- AbstractSourceWrapper
- Avatar::Source::Wrapper::RailsAssetSourceWrapper
- Defined in:
- lib/avatar/source/wrapper/rails_asset_source_wrapper.rb
Overview
Wraps a Source using Rails’ AssetTagHelper#image_path
, which can turn path URLs (e.g. ‘/images/my_avatar.png’) into absolute URLs( e.g. ‘’).
Instance Attribute Summary
Attributes inherited from AbstractSourceWrapper
Instance Method Summary collapse
-
#initialize(source) ⇒ RailsAssetSourceWrapper
constructor
A new instance of RailsAssetSourceWrapper.
-
#wrap(url, person, options = {}) ⇒ Object
Passes
url
toAssetTagHelper#image_path
.
Methods inherited from AbstractSourceWrapper
Methods included from AbstractSource
Constructor Details
#initialize(source) ⇒ RailsAssetSourceWrapper
Returns a new instance of RailsAssetSourceWrapper.
17 18 19 20 21 |
# File 'lib/avatar/source/wrapper/rails_asset_source_wrapper.rb', line 17 def initialize(source) super @url_helper = Object.new @url_helper.extend(ActionView::Helpers::AssetTagHelper) end |
Instance Method Details
#wrap(url, person, options = {}) ⇒ Object
Passes url
to AssetTagHelper#image_path
. Raises an error if it cannot generate a fully-qualified URI. Try setting ActionController::Base.asset_host
to avoid this error.
27 28 29 30 31 32 |
# File 'lib/avatar/source/wrapper/rails_asset_source_wrapper.rb', line 27 def wrap(url, person, = {}) # url will never be nil b/c of guarantee in AbstractSourceWrapper result = url_helper.image_path(url) raise "could not generate protocol and host for #{url}. Have you set ActionController::Base.asset_host?" unless result =~ /^http[s]?\:\/\// result end |