Permalink
Browse files

Made some more progress on laying out productions. Moved some stuff

around to make it easier to generate wrappers.
  • Loading branch information...
1 parent 6f9a48f commit 83108dee126f3e1ef67922e0e92bc62d279e6c75 @cpoirier committed Mar 29, 2012
@@ -171,6 +171,10 @@ def production_wrappers_module()
Wrappers::Productions
end
+ def placeholder_wrappers_module()
+ Wrappers::Placeholders
+ end
+
def identifier_type()
@type_manager.identifier_type
end
@@ -45,6 +45,23 @@ def initialize( context, model )
attr_reader :model, :adapter, :context
+ def wrap( model )
+ case model
+ when Schemaform::Model::Component
+ if @model.is_a?(Schemaform::Model::Component) || @model.is_a?(Schemaform::Model::Schema) then
+ @adapter.model_wrappers_module.const_get(model.class.unqualified_name).new(self, model)
+ else
+ model
+ end
+ when Schemaform::Language::Productions::Production
+ @adapter.production_wrappers_module.const_get(model.class.unqualified_name).new(self, model)
+ when Schemaform::Language::Placeholders::Placeholder
+ @adapter.placeholder_wrappers_module.const_get(model.class.unqualified_name).new(self, model)
+ else
+ model
+ end
+ end
+
def each_context()
result = nil
current = @context
@@ -29,24 +29,7 @@ module GenericSQL
module Wrappers
class Model
- class Wrapper < Wrapper
-
- def wrap( model )
- if model.is_a?(Schemaform::Model::Component) then
- @adapter.model_wrappers_module.const_get(model.class.unqualified_name).new(self, model)
- else
- nil
- end
- end
-
- def wrap_production( production )
- if model.is_a?(Schemaform::Language::Production) then
- @adapter.production_wrappers_module.const_get(production.class.unqualified_name).new(self, model)
- else
- nil
- end
- end
-
+ class Wrapper < Wrapper
end
@@ -154,7 +137,8 @@ def lay_out()
class Attribute
def initialize( context, model )
super(context, model)
- @type = wrap(model.type)
+ @type = wrap(model.type)
+ @formula = wrap(model.instance_eval{@formula}) # We go direct because we don't want to trigger any new processing
end
attr_reader :type
@@ -195,10 +179,7 @@ def present_flag_name()
class DerivedAttribute
def lay_out()
- Schemaform.debug.dump("skipping derived attribute #{name}")
- Schemaform.debug.print(@model.formula)
- exit
-
+ @formula.lay_out()
end
end
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby
+# =============================================================================================
+# Schemaform
+# A DSL giving the power of spreadsheets in a relational setting.
+#
+# [Website] http://schemaform.org
+# [Copyright] Copyright 2004-2012 Chris Poirier
+# [License] Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# =============================================================================================
+
+require Schemaform.locate("schemaform/model/schema.rb")
+
+#
+# Defines wrappers for the Language::Placeholders classes.
+
+module Schemaform
+module Adapters
+module GenericSQL
+module Wrappers
+class Placeholders
+
+ class Wrapper < Wrapper
+ end
+
+
+ #
+ # Create wrapper classes for all Placeholder classes.
+
+ extend Common
+ Schemaform::Language::Placeholders.constants(false).each do |constant|
+ create_wrapper_class(Schemaform::Language::Placeholders.const_get(constant))
+ end
+
+
+ class Placeholder
+ def initialize( context, model )
+ super(context, model)
+ @production = wrap(model.get_production)
+ end
+
+ def lay_out()
+ @production.lay_out() if @production
+ end
+ end
+
+
+
+
+
+end # Placeholders
+end # Wrappers
+end # GenericSQL
+end # Adapters
+end # Schemaform
@@ -30,6 +30,16 @@ module Wrappers
class Productions
class Wrapper < Wrapper
+ def initialize( context, model )
+ super(context, model)
+ model.each do |name, value|
+ instance_variable_set("@#{name}", wrap(value))
+ end
+ end
+
+ def lay_out()
+ fail_todo self.class.name
+ end
end
@@ -42,13 +52,12 @@ class Wrapper < Wrapper
end
-
class OrderBy
- def initialize(context, model)
- super(context, model)
-
+ def lay_out()
+ @relation.lay_out()
end
end
+
@@ -86,6 +86,6 @@ def get_description()
end # EntityTuple
-end # Placeholders
+end # Placeholder
end # Language
end # Schemaform
@@ -31,7 +31,7 @@ class Placeholder
def initialize( type, production = nil )
type_check(:type , type , Model::Type)
- type_check(:production, production, Production, true)
+ type_check(:production, production, Productions::Production, true)
@type = type
@production = production
end
@@ -24,15 +24,15 @@
module Schemaform
module Language
- #
- # Base class for productions -- things that describe who a Placeholder was calculated.
-
- class Production < PrintableStruct
- end # Production
-
module Productions
+ #
+ # Base class for productions -- things that describe who a Placeholder was calculated.
+
+ class Production < PrintableStruct
+ end # Production
+
# ==========================================================================================
# Basic

0 comments on commit 83108de

Please sign in to comment.