Module: RubyCodeAPI::Query

Included in:
Ruby::Node
Defined in:
lib/query/find.rb

Defined Under Namespace

Classes: FindError

Constant Summary collapse

NODES =

Use this to generate all methods except for find_block which is a bit special

{
  :module => Ruby::Module, 
  :class => Ruby::Class, 
  :variable => [Ruby::Variable, :token], 
  :assignment => [Ruby::Assignment, :left_token], 
  :call => Ruby::Call, 
  :def => Ruby::Method
}

Instance Method Summary collapse

Instance Method Details

#find(type, name, options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/query/find.rb', line 18

def find(type, name, options = {}, &block) 
  s = send :"find_#{type.to_s}", name, options
  s.extend(options[:extend]) if options[:extend] 
  if block_given?
    block.arity < 1 ? s.instance_eval(&block) : block.call(s)      
  else
    s
  end
end

#find_block(name, options = {}) ⇒ Object



53
54
55
56
# File 'lib/query/find.rb', line 53

def find_block(name, options = {})  
  options.merge!(:block => true) if !options.has_key?(:block_params)    
  find_by(:identifier, Ruby::Call, name, options)      
end

#find_by(key, type, name, options) ⇒ Object



48
49
50
51
# File 'lib/query/find.rb', line 48

def find_by(key, type, name, options)
  options.merge!(key => name)
  get_obj.select(type, options).first
end

#inside(type, name, options = {}, &block) ⇒ Object

Raises:



28
29
30
31
# File 'lib/query/find.rb', line 28

def inside(type, name, options = {}, &block) 
  raise FindError, "Must have block argument" if !block_given?
  find(type, name, options = {}, &block)       
end