lib/glue/property.rb in glue-0.15.0 vs lib/glue/property.rb in glue-0.16.0
- old
+ new
@@ -1,15 +1,15 @@
# * George Moschovitis <gm@navel.gr>
# * Michael Neumann <mneumann@ntecs.de>
# (c) 2004-2005 Navel, all rights reserved.
-# $Id: property.rb 326 2005-03-28 11:07:17Z gmosx $
+# $Id: property.rb 20 2005-04-15 15:18:36Z gmosx $
require 'glue/attribute'
require 'glue/array'
require 'glue/hash'
-module N
+module Glue
# Ruby attributes are typeless and generally this is good.
# Some times we need extra metadata though, for example in
# relational mapping, or web form population.
#
@@ -89,12 +89,12 @@
# gmosx: Perhaps we 'll optimize this in the future.
#++
def self.enchant(target, force = false)
unless target.instance_variables.include?('@__props')
- target.instance_variable_set('@__meta', N::SafeHash.new)
- target.instance_variable_set('@__props', N::SafeArray.new)
+ target.instance_variable_set('@__meta', Glue::SafeHash.new)
+ target.instance_variable_set('@__props', Glue::SafeArray.new)
# gmosx: Ruby surprises and amazes me! We are in the Metaclass
# when defining methods and attributes so @__props is really
# a class scoped variable that unlike @@__props is not shared
# through the hierarchy.
@@ -122,12 +122,12 @@
# Add some extra code to append features to
# subclasses.
target.module_eval %{
def self.inherited(child)
- N::PropertyUtils.enchant(child)
- N::PropertyUtils.copy_props(self, child)
+ Glue::PropertyUtils.enchant(child)
+ Glue::PropertyUtils.copy_props(self, child)
# gmosx: We have to define @@__props first to avoid reusing
# the hash from the module. super must stay at the end.
super
end
}
@@ -137,15 +137,15 @@
# Add some extra code for modules to append
# their features to classes that include it.
target.module_eval %{
def self.append_features(base)
- N::PropertyUtils.enchant(base)
- N::PropertyUtils.copy_props(self, base)
+ Glue::PropertyUtils.enchant(base)
+ Glue::PropertyUtils.copy_props(self, base)
# gmosx: We have to define @@__props first to avoid reusing
# the hash from the module. super must stay at the end.
- N::PropertyUtils.include_meta_mixins(base)
+ Glue::PropertyUtils.include_meta_mixins(base)
super
end
}
end
@@ -228,11 +228,11 @@
code = %{
def #{s}=(val)
}
- if N::Property.type_checking
+ if Glue::Property.type_checking
code << %{
unless #{prop.klass} == val.class
raise "Invalid type, expected '#{prop.klass}', is '\#\{val.class\}'."
end
}
@@ -253,13 +253,14 @@
end
# Include meta-language mixins
def self.include_meta_mixins(target)
- target.module_eval %{ include N::Validation } if defined?(N::Validation)
+ target.module_eval %{ include Glue::Validation } if defined?(Glue::Validation)
# gmosx: TODO, make Og::MetaLanguage equivalent to Validation.
target.module_eval %{ extend Og::MetaLanguage } if defined?(Og::MetaLanguage)
+ target.module_eval %{ include Glue::Aspects } if defined?(Glue::Aspects)
end
# Resolves the parameters passed to the propxxx macros
# to generate the meta, klass and symbols variables. This
# way the common functionality is factored out.
@@ -312,16 +313,16 @@
# --> creates only writer.
# prop Fixnum, :oid, writer = true, :sql => "integer PRIMARY KEY"
# --> creates reader and writer.
def prop(*params)
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
symbol = symbols.first
- N::PropertyUtils.enchant(self)
+ Glue::PropertyUtils.enchant(self)
- property = N::Property.new(symbol, klass, meta)
+ property = Glue::Property.new(symbol, klass, meta)
reader = meta[:reader] || true
writer = writer || meta[:writer] || false
meta[:reader] = true if meta[:reader].nil?
@@ -329,25 +330,25 @@
meta[:writer] = writer
else
meta[:writer] = true if meta[:writer].nil?
end
- N::PropertyUtils.add_prop(self, property)
+ Glue::PropertyUtils.add_prop(self, property)
# gmosx: should be placed AFTER enchant!
- N::PropertyUtils.include_meta_mixins(self)
+ Glue::PropertyUtils.include_meta_mixins(self)
end
# Helper method. Accepts a collection of symbols and generates
# properties. Only generates reader.
#
# Example:
# prop_reader String, :name, :title, :body, :sql => "char(32)"
def prop_reader(*params)
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
meta[:reader] = true
meta[:writer] = false
for symbol in symbols
@@ -360,11 +361,11 @@
#
# Example:
# prop_writer String, :name, :title, :body, :sql => "char(32)"
def prop_writer(*params)
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
meta[:reader] = false
meta[:writer] = true
for symbol in symbols
@@ -377,11 +378,11 @@
#
# Example:
# prop_accessor String, :name, :title, :body, :sql => "char(32)"
def prop_accessor(*params)
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
meta[:reader] = true
meta[:writer] = true
for symbol in symbols
@@ -398,10 +399,10 @@
#++
def meta(key, *val)
val = val.first if val.size == 1
- N::PropertyUtils.enchant(self)
+ Glue::PropertyUtils.enchant(self)
self.module_eval %{
@__meta[key] ||= []
@__meta[key].delete_if { |v| val == v }
@__meta[key] << val