From b02097f009a3f7b5562ad9865fc97370592ec0b6 Mon Sep 17 00:00:00 2001 From: snusnu Date: Tue, 21 May 2013 16:27:54 +0200 Subject: [PATCH] Don't rely on adamantium and concord in the README Also changes the integration spec to not rely on those two libraries. --- README.md | 64 +++++++++++++------ .../substation/dispatcher/call_spec.rb | 64 +++++++++++++------ 2 files changed, 90 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 6fbaffc..b8ee1c6 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 @@ -373,7 +400,6 @@ module App class Action include AbstractType - include Adamantium::Flat def self.call(request) new(request).call @@ -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({ diff --git a/spec/integration/substation/dispatcher/call_spec.rb b/spec/integration/substation/dispatcher/call_spec.rb index 15979f7..3290303 100644 --- a/spec/integration/substation/dispatcher/call_spec.rb +++ b/spec/integration/substation/dispatcher/call_spec.rb @@ -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) @@ -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 @@ -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 @@ -88,7 +115,6 @@ def call(name, input = nil) class Action include AbstractType - include Adamantium::Flat def self.call(request) new(request).call @@ -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({