Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'open-uri'
class RemoteSnippets
class << self
def get(key)
url = @mappings[key]
open(url).read
end
def register(key, url)
@mappings ||= {}
@mappings[key] = url
end
def []=(key, url)
register key, url
end
def [](key)
get key
end
end
end
# usage:
# in an initializer create some mappings:
# RemoteSnippets.register("header", "http://www.propublica.org/rails/header")
#
# or
#
# RemoteSnippets["header"] = "http://www.propublica.org/rails/header"
#
# and then in templates use either:
#
# RemoteSnippets.get("header")
#
# or
#
# RemoteSnippets["header"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.