Module: RubyCodeAPI::Query

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

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



15
16
17
18
19
20
21
22
23
# File 'lib/query/find.rb', line 15

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



50
51
52
53
# File 'lib/query/find.rb', line 50

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



45
46
47
48
# File 'lib/query/find.rb', line 45

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:

  • (StandardError)


25
26
27
28
# File 'lib/query/find.rb', line 25

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