lib/activefacts/generate/ruby.rb in activefacts-0.7.0 vs lib/activefacts/generate/ruby.rb in activefacts-0.7.1
- old
+ new
@@ -1,16 +1,24 @@
#
-# Generate Ruby for the ActiveFacts API from an ActiveFacts vocabulary.
-# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
+# ActiveFacts Generators.
+# Generate Ruby classes for the ActiveFacts API from an ActiveFacts vocabulary.
#
+# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
+#
require 'activefacts/vocabulary'
require 'activefacts/generate/oo'
module ActiveFacts
-
module Generate
+ # Generate Ruby module containing classes for an ActiveFacts vocabulary.
+ # Invoke as
+ # afgen --ruby[=options] <file>.cql
+ # Options are comma or space separated:
+ # * help list available options
+ # * sql Emit the sql mapping for tables/columns (REVISIT: not functional at present)
class RUBY < OO
+ private
def set_option(option)
@sql ||= false
case option
when 'help', '?'
@@ -129,10 +137,10 @@
def unary_dump(role, role_name)
puts " maybe :"+role_name
end
def role_dump(role)
- other_role = role.fact_type.all_role[role.fact_type.all_role[0] != role ? 0 : -1]
+ other_role = role.fact_type.all_role.select{|r| r != role}[0] || role
if @ar_by_role and @ar_by_role[other_role] and @sql
puts " # role #{role.fact_type.describe(role)}: absorbs in through #{preferred_role_name(other_role)}: "+@ar_by_role[other_role].map(&:column_name)*", "
end
super
end