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

Returns a new instance of CompilationContext.



103
104
105
106
107
108
109
# File 'lib/epuber/compiler/compilation_context.rb', line 103

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)

Returns:



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

def book
  @book
end

#file_resolverEpuber::Compiler::FileResolver



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

def file_resolver
  @file_resolver
end

#release_buildBool

Returns:

  • (Bool)


81
82
83
# File 'lib/epuber/compiler/compilation_context.rb', line 81

def release_build
  @release_build
end

#should_checkBool

Returns:

  • (Bool)


73
74
75
# File 'lib/epuber/compiler/compilation_context.rb', line 73

def should_check
  @should_check
end

#should_writeBool

Returns:

  • (Bool)


77
78
79
# File 'lib/epuber/compiler/compilation_context.rb', line 77

def should_write
  @should_write
end

#source_file_databaseEpuber::Compiler::FileDatabase (readonly)

This will track source files regardless of current target



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

def source_file_database
  @source_file_database
end

#targetEpuber::Book::Target (readonly)



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

def target
  @target
end

#target_file_databaseEpuber::Compiler::FileDatabase (readonly)

This will track source files depend on current target



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

def target_file_database
  @target_file_database
end

#use_cacheBool

Returns:

  • (Bool)


85
86
87
# File 'lib/epuber/compiler/compilation_context.rb', line 85

def use_cache
  @use_cache
end

#verboseBool

Returns:

  • (Bool)


89
90
91
# File 'lib/epuber/compiler/compilation_context.rb', line 89

def verbose
  @verbose
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/epuber/compiler/compilation_context.rb', line 95

def debug?
  !release_build
end

#incremental_build?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/epuber/compiler/compilation_context.rb', line 99

def incremental_build?
  use_cache
end

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

Returns nil.

Parameters:

  • klass (Class)

    class of thing you want to perform (Checker or Transformer)

  • source_type (Symbol)

    source type of that thing (Checker or Transformer)

Yields:

Yield Parameters:

Returns:

  • nil



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

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

      yield instance
    end
  end
end

#pluginsArray<Epuber::Plugin>

Returns:



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

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

#verbose?Boolean

Returns:

  • (Boolean)


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

def verbose?
  verbose
end