lib/luruju/jude_api/jude_base.rb in luruju-0.1.0 vs lib/luruju/jude_api/jude_base.rb in luruju-0.2.0
- old
+ new
@@ -1,2 +1,90 @@
require 'luruju/jude_api/add_dynamic_method'
-require 'luruju/jude_api/add_method'
+
+module Luruju
+
+ module JudeApi
+
+ class JudeBase
+
+ attr_writer :tagged
+ attr_reader :members
+
+ def initialize(members) @members = members end
+
+ def search options={}, &block
+ JudeBase.search members, options, &block
+ end
+
+ def tagged
+ return @tagged if @tagged
+ @tagged = HashWithIndifferentAccess.new
+ tagged_values.each {|x| @tagged[x.key.to_sym] = x.value}
+ @tagged
+ end
+
+ def self.search members, options={}
+ members.collect do |member|
+ if options.key?(:name)
+ next unless member.is_a?(JudeNamedElementMethods)
+ next unless member.name == options[:name]
+ end
+ next if options.key?(:id) and member.id != options[:id]
+ if block_given?
+ next unless yield(member)
+ end
+ member
+ end.compact
+ end
+
+ def inspect() "<#{self.class}: id=#{self.instance_eval('@id')}>" end
+
+ end
+
+ module JudeNamedElementAddMethod
+ def inspect() "<#{self.class}: name=#{self.name} id=#{self.instance_eval('@id')}>" end
+ end
+
+ module JudeErAttributeAddMethod
+ def constraint(constraint_name) constraints.find{|x|constraint_name == x.name} end
+ end
+
+ module JudeModelAddMethod
+ attr_accessor :mtime
+ end
+
+ module JudeClassAddMethod
+ def default?
+ return unless owner
+ return unless owner.kind_of_element?
+ return unless owner.owner
+ ['lang', 'util'].include?(owner.name) and owner.owner.name == 'java'
+ end
+
+ def super_classes() generalizations.collect{|g|g.super_type} end
+ def sub_classes() specializations.collect{|s|s.sub_type} end
+
+ end
+
+ module JudeAttributeAddMethod
+ def broad_aggregate?() is_aggregate? or is_composite? end
+ def not_broad_aggregate?() !broad_aggregate? end
+ def contra() association.attributes.find{|b|b != self} end
+ end
+
+ end
+
+end
+
+class Class
+
+ alias :include_except_luruju :include
+
+ def include *included
+ return include_except_luruju(*included) unless self.ancestors.include?(Luruju::JudeApi::JudeBase)
+ if Luruju::JudeApi.constants.include? "#{self.name}AddMethod".split("::").last
+ included[0].send :include, eval("#{self.name}AddMethod")
+ end
+ include_except_luruju(*included)
+ end
+
+end