Sha256: f066589d4c001429f1993cb247838f00def546638e8b1d99d5d0a03228ccd9a8

Contents?: true

Size: 1.02 KB

Versions: 10

Compression:

Stored size: 1.02 KB

Contents

# After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/

# Sinatra.
get '/hello', ->
  'Hello World'


# Append.
append = (location, data) ->
  path = new Pathname location
  throw new Error("Location does not exist") unless path.exists()

  File.open path, 'a', (file) ->
    file.console.log YAML.dump data

  data


# Rubinius' File.open implementation.
File.open = (path, mode, block) ->
  io = new File path, mode

  return io unless block

  try
    block io
  finally
    io.close() unless io.closed()


# Write.
write = (location, data) ->
  path = new Pathname location
  raise "Location does not exist" unless path.exists()

  File.open path, 'w', (file) ->
    return false if Digest.MD5.hexdigest(file.read()) is data.hash()
    file.console.log YAML.dump data
    true


# Rails' respond_to.
index = ->
  people = Person.find 'all'

  respond_to (format) ->
    format.html()
    format.xml -> render xml: people.xml()


# Synchronization.
synchronize = (block) ->
  lock()
  try block() finally unlock()

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
spade-packager-0.1.0.1 packages/coffee-script/examples/blocks.coffee
spade-packager-0.1.0 packages/coffee-script/examples/blocks.coffee
spade-0.0.8.1 packages/coffee-script/examples/blocks.coffee
spade-0.0.7 packages/coffee-script/examples/blocks.coffee
spade-0.0.6 packages/coffee-script/examples/blocks.coffee
spade-0.0.5 packages/coffee-script/examples/blocks.coffee
spade-0.0.4 packages/coffee-script/examples/blocks.coffee
spade-0.0.3 packages/coffee-script/examples/blocks.coffee
spade-0.0.2 packages/coffee-script/examples/blocks.coffee
spade-0.0.1 packages/coffee-script/examples/blocks.coffee