Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 28, 2012
@txus DCI example in Noscript b9850ad
Showing with 43 additions and 0 deletions.
  1. +35 −0 examples/dci.ns
  2. +8 −0 test/integration_test.rb
View
35 examples/dci.ns
@@ -0,0 +1,35 @@
+# DCI (Data-Context-Interaction)
+# ------------------------------
+
+# Models - plain, dumb data containers define what the system **is**.
+User = Object.clone({
+ cart: []
+})
+Book = Object.clone()
+
+# Roles - define what the system **does**.
+Customer = Trait.build('Customer', {
+ add to cart: -> book
+ @cart << book
+ end
+})
+
+# Define the use case (a Context): A user adds a book to his cart.
+add to cart context = -> user, book
+ user.uses(Customer)
+ user.add to cart(book)
+end
+
+# Runtime program (what a controller would do in a web application)
+# ---------------
+
+# We initialize the objects:
+john = User.clone()
+book = Book.clone()
+
+# We apply the context on these objects.
+add to cart context(john, book) # Execute the context
+
+# And now John has one item in his cart!
+msg = 'John has now %i elements in his cart' % john.cart.length()
+msg.puts()
View
8 test/integration_test.rb
@@ -37,6 +37,14 @@ def test_objects
], output
end
+ def test_dci
+ output = `./bin/noscript examples/dci.ns`.split("\n")
+
+ assert_equal [
+ "John has now 1 elements in his cart"
+ ], output
+ end
+
def test_traits
output = `./bin/noscript examples/traits.ns`.split("\n")

No commit comments for this range

Something went wrong with that request. Please try again.