Class: RDL::Query
Class Method Summary collapse
-
.class_query(q) ⇒ Object
Return an ordered list of all method types of a class.
-
.method_query(q) ⇒ Object
Return a pair [name, array of the types] for the method specified by q.
-
.method_type_query(q) ⇒ Object
Returns sorted list of pairs [method name, type] matching query.
Class Method Details
.class_query(q) ⇒ Object
Return an ordered list of all method types of a class. The query should be a class name.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rdl/query.rb', line 24 def self.class_query(q) klass = q.to_s return nil unless $__rdl_info.info.has_key? klass cls_meths = [] cls_klass = RDL::Util.add_singleton_marker(klass) if $__rdl_info.info.has_key? cls_klass then $__rdl_info.info[cls_klass].each { |meth, kinds| if kinds.has_key? :type then kinds[:type].each { |t| cls_meths << [meth.to_s, t] } end } end inst_meths = [] if $__rdl_info.info.has_key? klass then $__rdl_info.info[klass].each { |meth, kinds| if kinds.has_key? :type then kinds[:type].each { |t| inst_meths << [meth.to_s, t] } end } end cls_meths.sort! { |p1, p2| p1[0] <=> p2[0] } cls_meths.each { |m, t| m.insert(0, "self.") } inst_meths.sort! { |p1, p2| p1[0] <=> p2[0] } return cls_meths + inst_meths end |
.method_query(q) ⇒ Object
Return a pair [name, array of the types] for the method specified by q. Valid queries are: Class#method - instance method Class.method - class method method - method of self’s class
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rdl/query.rb', line 7 def self.method_query(q) klass = nil meth = nil if q =~ /(.+)#(.+)/ then klass = $1 meth = $2.to_sym elsif q =~ /(.+)\.(.+)/ then klass = RDL::Util.add_singleton_marker($1) meth = $2.to_sym # else # klass = self.class.to_s # meth = q.to_sym end return $__rdl_info.get(klass, meth, :type) end |
.method_type_query(q) ⇒ Object
Returns sorted list of pairs [method name, type] matching query. The query should be a string containing a method type query.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rdl/query.rb', line 51 def self.method_type_query(q) q = $__rdl_parser.scan_str "#Q #{q}" result = [] $__rdl_info.info.each { |klass, meths| meths.each { |meth, kinds| if kinds.has_key? :type then kinds[:type].each { |t| if q.match(t) result << [RDL::Util.pp_klass_method(klass, meth), t] end } end } } result.sort! { |p1, p2| p1[0] <=> p2[0] } return result end |