Class: Mactag::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/mactag/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



5
6
7
# File 'lib/mactag/builder.rb', line 5

def initialize
  @tags = []
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



3
4
5
# File 'lib/mactag/builder.rb', line 3

def tags
  @tags
end

Class Method Details

.builderObject



63
64
65
# File 'lib/mactag/builder.rb', line 63

def builder
  @builder
end

.createObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mactag/builder.rb', line 38

def create
  unless gem_home_exists?
    raise Mactag::MactagError.new("Gem home directory '#{Mactag::Config.gem_home}' does not exist")
  end

  if builder.has_gems?
    Mactag::Ctags.new(@builder.files, Mactag::Config.tags_file).create

    puts "[done] Successfully generated #{Mactag::Config.tags_file} file"
  else
    raise Mactag::MactagError.new('Nothing to tag')
  end
end

.gem_home_exists?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/mactag/builder.rb', line 59

def gem_home_exists?
  File.directory?(Mactag::Config.gem_home)
end

.generate(&block) ⇒ Object



52
53
54
55
56
57
# File 'lib/mactag/builder.rb', line 52

def generate(&block)
  @builder = Mactag::Builder.new

  dsl = Mactag::Dsl.new(@builder)
  dsl.instance_eval(&block)
end

Instance Method Details

#<<(tags) ⇒ Object



9
10
11
# File 'lib/mactag/builder.rb', line 9

def <<(tags)
  @tags += Array(tags)
end

#allObject



29
30
31
# File 'lib/mactag/builder.rb', line 29

def all
  @all ||= @tags.collect!(&:tag)
end

#directoriesObject



25
26
27
# File 'lib/mactag/builder.rb', line 25

def directories
  files.collect { |file| File.dirname(file) }.uniq
end

#filesObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mactag/builder.rb', line 13

def files
  tags = all
  tags.flatten!
  tags.compact!
  tags.collect! { |file| File.expand_path(file) }
  tags.collect! { |file| Dir.glob(file) }
  tags.flatten!
  tags.uniq!
  tags.reject! { |file| File.directory?(file) }
  tags
end

#has_gems?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mactag/builder.rb', line 33

def has_gems?
  all.flatten.compact.any?
end