Sha256: 4e5a1519b4964c37b153e2e809c19284b8da94c8a1d7baf55e09c00d70ba8435

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

require "social_avatar_proxy/app"
require "social_avatar_proxy/path_helpers"

module SocialAvatarProxy
  class Engine < ::Rails::Engine
    endpoint App
    
    def self.mounted_at
      @mounted_at ||= calculate_mounted_at
    end
    
    def self.calculate_mounted_at
      route ||= Rails.application.routes.routes.detect do |route|
        route.app == self
      end
      # if it's not found, it's not mounted
      unless route
        raise "#{self} is not yet mounted."
      end
      # return the route with it's slashes stripped
      route.path.spec.to_s.gsub(/^\/|\/$/, "")
    end
    
    module Helpers
      def twitter_avatar_path(identifier)
        "/#{SocialAvatarProxy::Engine.mounted_at}/twitter/#{identifier}"
      end
      
      def facebook_avatar_path(identifier)
        "/#{SocialAvatarProxy::Engine.mounted_at}/facebook/#{identifier}"
      end
    end
    
    ActionController::Base.send(:include, Helpers)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
social-avatar-proxy-0.0.8 lib/social_avatar_proxy/engine.rb