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.



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

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)


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

def release_build
  @release_build
end

#should_checkBool

Returns:

  • (Bool)


71
72
73
# File 'lib/epuber/compiler/compilation_context.rb', line 71

def should_check
  @should_check
end

#should_writeBool

Returns:

  • (Bool)


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

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)


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

def use_cache
  @use_cache
end

#verboseBool

Returns:

  • (Bool)


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

def verbose
  @verbose
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


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

def debug?
  !release_build
end

#incremental_build?Boolean

Returns:

  • (Boolean)


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

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



53
54
55
56
57
58
59
60
61
62
63
64
# 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

      yield instance
    end
  end
end

#pluginsArray<Epuber::Plugin>

Returns:



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

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
    UI.error "Can't find plugin at path #{path}"
  end.compact
end

#release_build?Boolean

Returns:

  • (Boolean)


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

def release_build?
  release_build
end

#verbose?Boolean

Returns:

  • (Boolean)


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

def verbose?
  verbose
end