Skip to content

Commit

Permalink
Don't rely on adamantium and concord in the README
Browse files Browse the repository at this point in the history
Also changes the integration spec to not rely on
those two libraries.
  • Loading branch information
snusnu committed May 21, 2013
1 parent caf66c9 commit b02097f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 38 deletions.
64 changes: 45 additions & 19 deletions README.md
Expand Up @@ -290,16 +290,28 @@ few simple actions.
module App

class Database
include Concord.new(:relations)
include Equalizer.new(:relations)

def initialize(relations)
@relations = relations
end

def [](relation_name)
Relation.new(relations[relation_name])
end

protected

attr_reader :relations

class Relation
include Concord.new(:tuples)
include Equalizer.new(:tuples)
include Enumerable

def initialize(tuples)
@tuples = tuples
end

def each(&block)
return to_enum unless block_given?
tuples.each(&block)
Expand All @@ -313,37 +325,45 @@ module App
def insert(tuple)
self.class.new(tuples + [tuple])
end

protected

attr_reader :tuples
end
end

module Models

class Person
include Concord.new(:attributes)
include Equalizer.new(:id, :name)

def id
attributes[:id]
end
attr_reader :id
attr_reader :name

def name
attributes[:name]
def initialize(attributes)
@id, @name = attributes.values_at(:id, :name)
end
end
end # module Models

class Environment
include Concord.new(:storage)
include Adamantium::Flat
include Equalizer.new(:storage)

attr_reader :storage

def initialize(storage)
@storage = storage
end
end

class Storage
include Concord.new(:db)
include Adamantium::Flat

include Equalizer.new(:db)
include Models

def initialize(db)
@db = db
end

def list_people
db[:people].all.map { |tuple| Person.new(tuple) }
end
Expand All @@ -356,14 +376,21 @@ module App
relation = db[:people].insert(:id => person.id, :name => person.name)
relation.map { |tuple| Person.new(tuple) }
end

protected

attr_reader :db
end

class App
include Concord.new(:dispatcher)
include Adamantium::Flat
include Equalizer.new(:dispatcher)

def initialize(dispatcher)
@dispatcher = dispatcher
end

def call(name, input = nil)
dispatcher.call(name, input)
@dispatcher.call(name, input)
end
end

Expand All @@ -373,7 +400,6 @@ module App
class Action

include AbstractType
include Adamantium::Flat

def self.call(request)
new(request).call
Expand Down Expand Up @@ -440,8 +466,8 @@ module App
end # module Actions

module Observers
LogEvent = Class.new { def self.call(response); end }
SendEmail = Class.new { def self.call(response); end }
LogEvent = Proc.new { |response| response }
SendEmail = Proc.new { |response| response }
end

DB = Database.new({
Expand Down
64 changes: 45 additions & 19 deletions spec/integration/substation/dispatcher/call_spec.rb
Expand Up @@ -5,16 +5,28 @@
module App

class Database
include Concord.new(:relations)
include Equalizer.new(:relations)

def initialize(relations)
@relations = relations
end

def [](relation_name)
Relation.new(relations[relation_name])
end

protected

attr_reader :relations

class Relation
include Concord.new(:tuples)
include Equalizer.new(:tuples)
include Enumerable

def initialize(tuples)
@tuples = tuples
end

def each(&block)
return to_enum unless block_given?
tuples.each(&block)
Expand All @@ -28,37 +40,45 @@ def all
def insert(tuple)
self.class.new(tuples + [tuple])
end

protected

attr_reader :tuples
end
end

module Models

class Person
include Concord.new(:attributes)
include Equalizer.new(:id, :name)

def id
attributes[:id]
end
attr_reader :id
attr_reader :name

def name
attributes[:name]
def initialize(attributes)
@id, @name = attributes.values_at(:id, :name)
end
end
end # module Models

class Environment
include Concord.new(:storage)
include Adamantium::Flat
include Equalizer.new(:storage)

attr_reader :storage

def initialize(storage)
@storage = storage
end
end

class Storage
include Concord.new(:db)
include Adamantium::Flat

include Equalizer.new(:db)
include Models

def initialize(db)
@db = db
end

def list_people
db[:people].all.map { |tuple| Person.new(tuple) }
end
Expand All @@ -71,14 +91,21 @@ def create_person(person)
relation = db[:people].insert(:id => person.id, :name => person.name)
relation.map { |tuple| Person.new(tuple) }
end

protected

attr_reader :db
end

class App
include Concord.new(:dispatcher)
include Adamantium::Flat
include Equalizer.new(:dispatcher)

def initialize(dispatcher)
@dispatcher = dispatcher
end

def call(name, input = nil)
dispatcher.call(name, input)
@dispatcher.call(name, input)
end
end

Expand All @@ -88,7 +115,6 @@ def call(name, input = nil)
class Action

include AbstractType
include Adamantium::Flat

def self.call(request)
new(request).call
Expand Down Expand Up @@ -155,8 +181,8 @@ def call
end # module Actions

module Observers
LogEvent = Class.new { def self.call(response); end }
SendEmail = Class.new { def self.call(response); end }
LogEvent = Proc.new { |response| response }
SendEmail = Proc.new { |response| response }
end

DB = Database.new({
Expand Down

0 comments on commit b02097f

Please sign in to comment.