Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Imagine a world, with wormholes between the rails-o-verse and the javascript-o-verse
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
spec
.gitignore
.rvmrc
Gemfile
Gemfile.lock
README.rdoc
Rakefile
wormhole.gemspec

README.rdoc

Wormhole

What the heck is this?

Wormhole is a simple concept, to provide a solution for getting configuration and runtime objects in a clean way from the rails-server-side into the javascript-client-side.

The Wormhole-object can contain several namespaces. Every namespace represents a configuration-object:

Wormhole.create(:my_namespace) do |c|
  # c is a config-object
  c.key_1 = "value"
  c.key_2 = 42
end

or:

c = Wormhole.create(:my_other_namespace)
c.key_1 = "value"
c.key_2 = 42

These initial namespace creations could be placed in the environment.rb or in another, perhaps self created file, that gets sourced by the rails-server on bootup.

Now, in every view, you can simply call:

<script><%= Wormhole.to_javascript %></script>

This will create the sourcecode for a javascript-object. In case of our two namespaces, the object would be used as followed:

<script>
  Wormhole.my_namespace.key_2 // returns 42
  Wormhole.my_other_namespace.key_1 // returns "value"
</script>

Beside this initial configuration, every namespace can be accessed and edited on a per-request and non-persistant way:

# in an action
Wormhole(:my_namespace) do |c|
  c.key_2 = 43
end

or:

c = Wormhole(:my_namespace)
c.key_2 = 43

In the correspondingly view, key_2 will now return the new value. But this change is not permanent, the underlying namespace is never mutable.

The omnious config-object

will follow..

Building the Gem

rake gem

Testing

gem install bundler
bundle install
rake

Documentation

  • build doc

    rake yard
  • then open +file:///path/to/gem/doc/index.html+ in your browser

TODO

  • Seed Wormhole::Config with (nested) values:

    Wormhole::Config.new(:key => { :subkey => :value })
Something went wrong with that request. Please try again.