require 'erb' module Luruju class JudeMeta def initialize() @interfaces = HashWithIndifferentAccess.new end @@instance = new def self.instance() @@instance end def self.instance=(instance) @@instance = instance end attr_accessor :interfaces def jude_class(jude_if_name) JudeApi.module_eval "Jude#{jude_if_name}" end def create_jude_if jude_if_name jude_if = JudeInterface.new jude_if.if_name = jude_if_name @interfaces[jude_if_name] = jude_if jude_if end def self.is_defined_for_luruju? jude_if JudeApi.const_defined? "Jude#{jude_if.if_name rescue jude_if}Methods" end def define_all() @interfaces.each_value{|i| i.define_for_luruju unless JudeMeta.is_defined_for_luruju?(i)} end class JudeInterface attr_accessor :if_name, :attributes, :super_if_names, :constants def initialize() @attributes, @super_if_names, @constants = [], [], {} end def super_ifs() @super_if_names.collect{|x|JudeMeta.instance.interfaces[x]} end def module_name() "Jude#{if_name}Methods" end def class_name() "Jude#{if_name}" end def define_for_luruju super_ifs.select{|x|!JudeMeta.is_defined_for_luruju?(x.if_name)}.each{|x|x.define_for_luruju} JudeApi.module_eval ERB.new(module_erb_def).result(binding) JudeApi.module_eval ERB.new(class_erb_def).result(binding) JudeApi.module_eval class_name end protected def module_erb_def return <<-EOD module <%= module_name %> <% super_ifs.each do |super_if| %> include <%= super_if.module_name %> <% end %> <% attributes.each do |attr| %> attr_accessor :<%= attr %> <% if /^is_/ =~ attr %> alias_method :<%= attr %>?, :<%= attr %> <% end %> <% end %> <% constants.each do |key,value| %> <%= key %> = <%= value %> <% end %> end EOD end def class_erb_def return <<-EOD class <%= class_name %> < JudeBase include <%= module_name %> end EOD end end end end