Module: DbAgile::RubyTools

Extended by:
RubyTools
Included in:
RubyTools
Defined in:
lib/dbagile/tools/ruby.rb

Instance Method Summary collapse

Instance Method Details

#class_unqualified_name(clazz) ⇒ Object Also known as: unqualified_class_name

Returns the unqualified name of a class



15
16
17
18
19
20
21
22
# File 'lib/dbagile/tools/ruby.rb', line 15

def class_unqualified_name(clazz)
  name = clazz.name
  if name =~ /::([^:]+)$/
    $1
  else
    name
  end
end

#extract_file_rdoc(file) ⇒ Object

Extracts the rdoc of a given ruby file source



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dbagile/tools/ruby.rb', line 39

def extract_file_rdoc(file)
  source, doc, started = File.read(file), "", false
  source.each_line{|line|
    if /^\s*[#]/ =~ line
      doc << line
      started = true
    elsif started
      break
    end 
  }
  doc.gsub(/^\s*[#] ?/, "")
end

#optional_args_block_call(block, args) ⇒ Object

Makes a call to a block that accepts optional arguments



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dbagile/tools/ruby.rb', line 26

def optional_args_block_call(block, args)
  if RUBY_VERSION >= "1.9.0"
    if block.arity == 0
      block.call
    else
      block.call(*args)
    end
  else
    block.call(*args)
  end
end

#parent_module(clazz) ⇒ Object

Returns the parent module of a class



5
6
7
8
9
10
11
12
# File 'lib/dbagile/tools/ruby.rb', line 5

def parent_module(clazz)
  name = clazz.name
  if name =~ /^(.*?)::([^:]+)$/
    Kernel.eval($1)
  else
    nil
  end
end

#rdoc_file_paragraphs(file) ⇒ Object

Convenient method for rdoc_paragraphs(extract_file_rdoc(file))



72
73
74
# File 'lib/dbagile/tools/ruby.rb', line 72

def rdoc_file_paragraphs(file)
  rdoc_paragraphs(extract_file_rdoc(file))
end

#rdoc_paragraphs(rdoc_text) ⇒ Object

Splits a text obtained through extract_file_rdoc into paragraphs



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dbagile/tools/ruby.rb', line 53

def rdoc_paragraphs(rdoc_text)
  paragraphs, current = [], ""
  rdoc_text.each_line do |s|
    if s.strip.empty?
      unless current.strip.empty?
        paragraphs << current 
      end
      current = ""
    else
      current << s
    end
  end
  unless current.strip.empty?
    paragraphs << current 
  end
  paragraphs
end