class Epuber::Config

Constants

WORKING_PATH

Attributes

test[RW]
bookspec[W]

@param [Epuber::Book] bookspec

@return [Epuber::Book]

release_build[RW]

@return [Boolean]

Public Class Methods

clear_instance!() click to toggle source
# File lib/epuber/config.rb, line 163
def clear_instance!
  @instance = nil
end
find_bookspec_files(dir) click to toggle source

Find all bookspec files in given directory

@param [String] dir

# File lib/epuber/config.rb, line 185
def find_bookspec_files(dir)
  Dir.chdir(dir) do
    Dir.glob('*.bookspec').map do |path|
      File.expand_path(path)
    end
  end
end
find_project_dir(dir) click to toggle source

Find project directory by searching for .bookspec files in current and parent directories

@param [String] dir @return [String, nil]

# File lib/epuber/config.rb, line 198
def find_project_dir(dir)
  return dir if find_bookspec_files(dir).any?

  parent = File.dirname(dir)
  return nil if parent == dir

  find_project_dir(parent)
end
instance() click to toggle source

Singleton

@return [Epuber::Config]

# File lib/epuber/config.rb, line 159
def instance
  @instance ||= new
end
load_bookspec(path, frozen: true) click to toggle source

@return [Epuber::Book]

# File lib/epuber/config.rb, line 169
def load_bookspec(path, frozen: true)
  require_relative 'book'

  book = Epuber::Book.from_file(path)
  book.finish_toc
  book.validate

  book.freeze if frozen

  book
end
test?() click to toggle source
# File lib/epuber/config.rb, line 151
def test?
  test
end

Public Instance Methods

bookspec() click to toggle source

@return [Epuber::Book]

# File lib/epuber/config.rb, line 50
def bookspec
  @bookspec ||= self.class.load_bookspec(bookspec_path)
end
bookspec_lockfile() click to toggle source

@return [Epuber::Lockfile]

# File lib/epuber/config.rb, line 66
def bookspec_lockfile
  @bookspec_lockfile ||= Lockfile.from_file(bookspec_lockfile_path) do |lockfile|
    lockfile.epuber_version = Epuber::VERSION
    lockfile.bade_version = Bade::VERSION
  end
end
bookspec_lockfile_path() click to toggle source

@return [String]

# File lib/epuber/config.rb, line 44
def bookspec_lockfile_path
  "#{bookspec_path}.lock"
end
bookspec_path() click to toggle source

@return [String]

# File lib/epuber/config.rb, line 38
def bookspec_path
  @bookspec_path ||= self.class.find_bookspec_files(project_path).first
end
build_cache_path(cache_name) click to toggle source

@param [String] cache_name

@return [String]

# File lib/epuber/config.rb, line 102
def build_cache_path(cache_name)
  File.join(working_path, 'build_cache', cache_name)
end
build_path(target) click to toggle source

@param [Epuber::Book::Target] target

@return [String]

# File lib/epuber/config.rb, line 86
def build_path(target)
  File.join(working_path, 'build', target.name.to_s)
end
file_stat_database_path() click to toggle source

@return [String]

# File lib/epuber/config.rb, line 108
def file_stat_database_path
  File.join(working_path, 'metadata', 'source_file_stats.yml')
end
pretty_path_from_project(of_file) click to toggle source

@param [String] of_file absolute path to file

@return [String] relative path to file from root of project

# File lib/epuber/config.rb, line 24
def pretty_path_from_project(of_file)
  Pathname.new(of_file.unicode_normalize)
          .relative_path_from(Pathname.new(project_path))
          .to_s
end
project_path() click to toggle source

@return [String] path to project directory (where .bookspec file is located or current directory if not found)

# File lib/epuber/config.rb, line 13
def project_path
  @project_path ||= begin
    path = self.class.find_project_dir(Dir.pwd) || Dir.pwd
    path.unicode_normalize
  end
end
release_build_path(target) click to toggle source

@param [Epuber::Book::Target] target

@return [String]

# File lib/epuber/config.rb, line 94
def release_build_path(target)
  File.join(working_path, 'release_build', target.name.to_s)
end
remove_build_caches() click to toggle source
# File lib/epuber/config.rb, line 140
def remove_build_caches
  FileUtils.rm_rf(File.join(working_path, 'build_cache'))
  FileUtils.rm_rf(File.join(working_path, 'build'))
  FileUtils.rm_rf(File.join(working_path, 'metadata'))
end
same_version_as_last_run?() click to toggle source
# File lib/epuber/config.rb, line 134
def same_version_as_last_run?
  !(bookspec_lockfile.epuber_version != Epuber::VERSION ||
      bookspec_lockfile.bade_version.nil? ||
      bookspec_lockfile.bade_version != Bade::VERSION)
end
save_lockfile() click to toggle source

@return nil

# File lib/epuber/config.rb, line 75
def save_lockfile
  bookspec_lockfile.epuber_version = Epuber::VERSION
  bookspec_lockfile.bade_version = Bade::VERSION

  bookspec_lockfile.write_to_file
end
target_file_stat_database_path(target) click to toggle source

@param [Epuber::Book::Target] target

@return [String]

# File lib/epuber/config.rb, line 116
def target_file_stat_database_path(target)
  File.join(working_path, 'metadata', 'target_stats', target.name.to_s, 'file_stats.yml')
end
warn_for_outdated_versions!() click to toggle source
# File lib/epuber/config.rb, line 120
    def warn_for_outdated_versions!
      if bookspec_lockfile.epuber_version > Epuber::VERSION
        UI.warning(<<~MSG.rstrip)
          Warning: the running version of Epuber is older than the version that created the lockfile. We suggest you upgrade to the latest version of Epuber by running `gem install epuber`.
        MSG
      end

      return unless bookspec_lockfile.bade_version && bookspec_lockfile.bade_version > Bade::VERSION

      UI.warning(<<~MSG.rstrip)
        Warning: the running version of Bade is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bade by running `gem install bade`.
      MSG
    end
working_path() click to toggle source

@return [String]

# File lib/epuber/config.rb, line 32
def working_path
  @working_path ||= File.join(project_path, WORKING_PATH)
end