Class: Epuber::Compiler::CompilationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/compiler/compilation_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book, target) ⇒ CompilationContext



109
110
111
112
113
114
115
# File 'lib/epuber/compiler/compilation_context.rb', line 109

def initialize(book, target)
  @book = book
  @target = target

  @source_file_database = FileDatabase.new(Config.instance.file_stat_database_path)
  @target_file_database = FileDatabase.new(Config.instance.target_file_stat_database_path(target))
end

Instance Attribute Details

#bookEpuber::Book (readonly)



8
9
10
# File 'lib/epuber/compiler/compilation_context.rb', line 8

def book
  @book
end

#file_resolverEpuber::Compiler::FileResolver



16
17
18
# File 'lib/epuber/compiler/compilation_context.rb', line 16

def file_resolver
  @file_resolver
end

#release_buildBool



83
84
85
# File 'lib/epuber/compiler/compilation_context.rb', line 83

def release_build
  @release_build
end

#should_checkBool



75
76
77
# File 'lib/epuber/compiler/compilation_context.rb', line 75

def should_check
  @should_check
end

#should_writeBool



79
80
81
# File 'lib/epuber/compiler/compilation_context.rb', line 79

def should_write
  @should_write
end

#source_file_databaseEpuber::Compiler::FileDatabase (readonly)

This will track source files regardless of current target



22
23
24
# File 'lib/epuber/compiler/compilation_context.rb', line 22

def source_file_database
  @source_file_database
end

#targetEpuber::Book::Target (readonly)



12
13
14
# File 'lib/epuber/compiler/compilation_context.rb', line 12

def target
  @target
end

#target_file_databaseEpuber::Compiler::FileDatabase (readonly)

This will track source files depend on current target



28
29
30
# File 'lib/epuber/compiler/compilation_context.rb', line 28

def target_file_database
  @target_file_database
end

#use_cacheBool



87
88
89
# File 'lib/epuber/compiler/compilation_context.rb', line 87

def use_cache
  @use_cache
end

#verboseBool



91
92
93
# File 'lib/epuber/compiler/compilation_context.rb', line 91

def verbose
  @verbose
end

Instance Method Details

#debug?Boolean



97
98
99
# File 'lib/epuber/compiler/compilation_context.rb', line 97

def debug?
  !release_build
end

#incremental_build?Boolean



101
102
103
# File 'lib/epuber/compiler/compilation_context.rb', line 101

def incremental_build?
  use_cache
end

#perform_plugin_things(klass, source_type) {|instance| ... } ⇒ Object

Returns nil.

Yields:

Yield Parameters:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/epuber/compiler/compilation_context.rb', line 53

def perform_plugin_things(klass, source_type)
  plugins.each do |plugin|
    plugin.instances(klass).each do |instance|
      # @type [Epuber::CheckerTransformerBase] instance

      next if instance.source_type != source_type
      next if instance.options.include?(:run_only_before_release) && !release_build

      location = instance.block.source_location.map(&:to_s).join(':')
      message = "performing #{source_type.inspect} from plugin #{location}"
      UI.print_step_processing_time(message) do
        yield instance
      end
    end
  end
end

#pluginsArray<Epuber::Plugin>



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/epuber/compiler/compilation_context.rb', line 32

def plugins
  @plugins ||= @target.plugins.map do |path|
    plugin = Plugin.new(path)
    plugin.files.each do |file|
      file_resolver.add_file(file)
    end
    plugin
  rescue LoadError => e
    UI.error "Can't find plugin at path #{path}, #{e}"
  end.compact
end

#release_build?Boolean



105
106
107
# File 'lib/epuber/compiler/compilation_context.rb', line 105

def release_build?
  release_build
end

#verbose?Boolean



93
94
95
# File 'lib/epuber/compiler/compilation_context.rb', line 93

def verbose?
  verbose
end