Sha256: 74161a832a4ed1eb0b627629d45d5850523884f6dc7e023ef044ae9a59e0e63b

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

require 'innate'

# This demonstrates how to obtain different content types from the return value
# of action methods.
#
# Try following requests:
#   /set/foo/bar
#   /set/duh/duf
#
#   /index.json
#   /index.yaml
#
#   /get/foo.json
#   /get/foo.yaml
# 
# Note that this functionality is quite experimental, but by strategically
# placing ressources in actions it may be possible to achieve interesting
# effects and interoperability with JavaScript at a low cost.
#
# TODO:
#   * parsing requests based on the content-type, but that's much less
#     straight-forward and would require some kind of convention?

class Dict
  include Innate::Node
  map '/'

  DICT = {}

  # /get/foo || /get/foo.json || /get/foo.yaml
  def get(key)
    {key => DICT[key]}
  end

  # /set/foo/bar || /set/foo/bar.json || /set/foo/bar.yaml
  def set(key, value)
    {key => (DICT[key] = value)}
  end

  # /index.json || /.json || /index.yaml || /.yaml
  def index
    DICT
  end
end

Innate.start

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
manveru-innate-2009.02.06 example/providing_hash.rb
manveru-innate-2009.02.21 example/providing_hash.rb