Skip to content

Instantly share code, notes, and snippets.

@rebo
Created January 11, 2013 17:00
Show Gist options
  • Select an option

  • Save rebo/4512300 to your computer and use it in GitHub Desktop.

Select an option

Save rebo/4512300 to your computer and use it in GitHub Desktop.
#
# Simple Context Example:
#
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
require 'hybrid_dci'
Foo = Struct.new(:name) do
include HybridDCI::Data
end
class SimpleContext
include HybridDCI::Context
role :greeter do
contract :name
def say_hi
puts "Hello there! says #{name}"
end
end
role :goodbye_guy do
contract :name
def say_bye
puts "Goodbye! says #{name}"
end
end
def initialize
@a_foo = Foo.new("Arthur")
bind_roles(:greeter => @a_foo, :goodbye_guy=> @a_foo)
end
def execute
in_context do
greeter(:call).say_hi
goodbye_guy(:call).say_bye
end
end
end
context = SimpleContext.new
context.execute
# =>
# >> Hello there! says Arthur
# >> Goodbye! says Arthur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment