Permalink
Browse files

Traded calls to .tap for cals to .use, which I've added to allow diff…

…erent semantics on nil.
  • Loading branch information...
1 parent 63a2e9c commit 59f6b4cacba59a07c52580b0bc3a72cfcd3f7e49 @cpoirier committed Mar 14, 2012
View
@@ -66,7 +66,7 @@ def self.define( name, version, &block )
@@schemas.register(VersionSet.new(name)) unless @@schemas.member?(name)
assert(!@@schemas[name].member?(version), "Schema #{name} version #{version} is already defined")
- Schema.new(name, version).tap do |schema|
+ Schema.new(name, version).use do |schema|
@@schemas[name][version] = schema
Language::SchemaDefinition.process(schema, &block)
end
@@ -115,7 +115,7 @@ def empty_name()
def define_table( *name )
- table_class.new(self, build_name(*name)).tap do |table|
+ table_class.new(self, build_name(*name)).use do |table|
@tables.register(table)
yield(table) if block_given?
end
@@ -38,7 +38,7 @@ def define_field( name, type, *modifiers )
end
def define_index( name, unique = false )
- @indices.register(@adapter.index_class.new(self, name, unique)).tap do |index|
+ @indices.register(@adapter.index_class.new(self, name, unique)).use do |index|
yield(index) if block_given?
end
end
@@ -106,7 +106,7 @@ def []( *names )
when Hash
@children.select{|field| names.member?(field.name)}
when Array
- [].tap do |fields|
+ [].use do |fields|
@children.each do |name, field|
fields << field if names.member?(field.name)
end
@@ -52,7 +52,7 @@ def each( tuple_name, &block )
@entity = Schema::DefinedEntity.new(@name, @parent)
@schema.entities.register(@entity)
- @entity.heading.tap do |tuple|
+ @entity.heading.use do |tuple|
assert( tuple.name.nil?, "expected unnamed tuple for EntityDefinition::each()")
tuple.name = tuple_name
@@ -115,7 +115,7 @@ def self.capture_logical_or( lhs, rhs )
def self.capture_formula( formula_context, block, result_type = nil, join_compatible_only = true )
formula_context.get_type.schema.enter do
- Language::FormulaDefinition.module_exec(formula_context, &block).tap do |captured_formula|
+ Language::FormulaDefinition.module_exec(formula_context, &block).use do |captured_formula|
type_check(:captured_formula, captured_formula, Language::Placeholder)
if result_type then
if join_compatible_only then
@@ -362,7 +362,7 @@ def formula()
schema.enter do
begin
@analyzing = true # Ensure any self-references don't retrigger analysis
- @formula = Language::FormulaCapture.capture_formula(root_tuple.placeholder(), @proc).tap do |captured_formula|
+ @formula = Language::FormulaCapture.capture_formula(root_tuple.placeholder(), @proc).use do |captured_formula|
type_check(:captured_formula, captured_formula, Language::Placeholder)
end
ensure
@@ -432,7 +432,7 @@ def formula()
schema.enter do
begin
@analyzing = true # Ensure any self-references don't retrigger analysis
- @formula = Language::FormulaDefinition.module_exec(&@proc).tap do |captured_formula|
+ @formula = Language::FormulaDefinition.module_exec(&@proc).use do |captured_formula|
type_check(:captured_formula, captured_formula, Language::Placeholder)
end
ensure
@@ -72,7 +72,7 @@ def self.not!( clause )
fail_todo
#
# boolean = FormulaCapture.resolve_type(:boolean)
- # clause = FormulaCapture.capture(clause).tap do |captured|
+ # clause = FormulaCapture.capture(clause).use do |captured|
# assert(boolean.assignable_from?(captured.get_type), "expected boolean expression for logical not, found #{lhs.get_type.description}")
# end
#
@@ -26,7 +26,7 @@ class SchemaDefinition
include QualityAssurance
def self.process( schema, &block )
- schema.tap do
+ schema.use do
dsl = new(schema)
schema.enter do
dsl.instance_eval(&block)
@@ -26,14 +26,14 @@ class TupleDefinition
include QualityAssurance
def self.build( name = nil, register = true, &block )
- Schema::Tuple.new(name).tap do |tuple|
+ Schema::Tuple.new(name).use do |tuple|
Schema.current.register_tuple(tuple) if name && register
TupleDefinition.process(tuple, &block)
end
end
def self.process( tuple, &block )
- tuple.tap do
+ tuple.use do
dsl = new(tuple)
dsl.instance_eval(&block)
end
@@ -139,14 +139,14 @@ def initialize( adapter )
@control_tables[:versions] = VersionTable.new(@adapter, Schemaform::MasterIdentifier)
# @adapter.instance_eval do
- # .tap do |control_schema|
+ # .use do |control_schema|
#
- # # tables[:configuration] = control_schema.define_table(make_name(:configuration, Schemaform::MasterIdentifier)).tap do |table|
+ # # tables[:configuration] = control_schema.define_table(make_name(:configuration, Schemaform::MasterIdentifier)).use do |table|
# # table.add_field field_class.new(table, :name , nil, text_field_type(50) )
# # table.add_field field_class.new(table, :value, nil, text_field_type(200))
# # end
#
- # # tables[:versions] = control_schema.define_table(make_name("versions", Schemaform::MasterIdentifier), "schema_id").tap do |table|
+ # # tables[:versions] = control_schema.define_table(make_name("versions", Schemaform::MasterIdentifier), "schema_id").use do |table|
# # table.add_field field_class.new(table, :name , nil, text_field_type(60))
# # table.add_field field_class.new(table, :version, nil, integer_field_type(1..1000000000))
# # end
@@ -88,7 +88,7 @@ def register_tuple( tuple )
def default()
return @default unless @default.nil?
- @default = {}.tap do |pairs|
+ @default = {}.use do |pairs|
@attributes.each do |name, attribute|
if attribute.writable? then
pairs[attribute.name] = attribute.resolve.default
@@ -106,13 +106,13 @@ def width()
end
def recreate_in( new_context, changes = nil )
- self.new().acquire_for(new_context).tap do |tuple|
+ self.new().acquire_for(new_context).use do |tuple|
recreate_children_in(tuple, changes)
end
end
def project(*names)
- Tuple.new(schema).tap do |projection|
+ Tuple.new(schema).use do |projection|
names.each do |name|
check{ assert(@attributes.member?(name), "no such attribute [#{name}]") }
if @attributes.member?(name) then
@@ -168,7 +168,7 @@ def find( name, fail_if_missing = true )
# Creates a copy of this registry, possibly with renamed members (if you supply a block).
def dup()
- Registry.new().tap do |copy|
+ Registry.new().use do |copy|
each do |name, value|
name = yield(name, value) if block_given?
copy.register(value, name)

0 comments on commit 59f6b4c

Please sign in to comment.