Class: Epuber::Config

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

Constant Summary collapse

WORKING_PATH =
'.epuber'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.testObject

Returns the value of attribute test.



149
150
151
# File 'lib/epuber/config.rb', line 149

def test
  @test
end

Class Method Details

.clear_instance!Object



163
164
165
# File 'lib/epuber/config.rb', line 163

def clear_instance!
  @instance = nil
end

.instanceEpuber::Config

Singleton

Returns:



159
160
161
# File 'lib/epuber/config.rb', line 159

def instance
  @instance ||= new
end

.load_bookspec(path, frozen: true) ⇒ Epuber::Book

Returns:



169
170
171
172
173
174
175
176
177
178
179
# 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?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/epuber/config.rb', line 151

def test?
  test
end

Instance Method Details

#bookspecEpuber::Book

Returns:



56
57
58
# File 'lib/epuber/config.rb', line 56

def bookspec
  @bookspec ||= self.class.load_bookspec(bookspec_path)
end

#bookspec=(bookspec) ⇒ Epuber::Book

Parameters:

Returns:



64
65
66
# File 'lib/epuber/config.rb', line 64

def bookspec=(bookspec)
  @bookspec = bookspec
end

#bookspec_lockfileEpuber::Lockfile

Returns:



70
71
72
73
74
75
# File 'lib/epuber/config.rb', line 70

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_pathString

Returns:

  • (String)


40
41
42
# File 'lib/epuber/config.rb', line 40

def bookspec_lockfile_path
  "#{bookspec_path}.lock"
end

#bookspec_pathString

Returns:

  • (String)


34
35
36
# File 'lib/epuber/config.rb', line 34

def bookspec_path
  @bookspec_path ||= find_all_bookspecs.first
end

#build_cache_path(cache_name) ⇒ String

Parameters:

  • cache_name (String)

Returns:

  • (String)


106
107
108
# File 'lib/epuber/config.rb', line 106

def build_cache_path(cache_name)
  File.join(working_path, 'build_cache', cache_name)
end

#build_path(target) ⇒ String

Parameters:

Returns:

  • (String)


90
91
92
# File 'lib/epuber/config.rb', line 90

def build_path(target)
  File.join(working_path, 'build', target.name.to_s)
end

#file_stat_database_pathString

Returns:

  • (String)


112
113
114
# File 'lib/epuber/config.rb', line 112

def file_stat_database_path
  File.join(working_path, 'metadata', 'source_file_stats.yml')
end

#find_all_bookspecsArray<String>

Returns:

  • (Array<String>)


46
47
48
49
50
51
52
# File 'lib/epuber/config.rb', line 46

def find_all_bookspecs
  Dir.chdir(project_path) do
    Dir.glob('*.bookspec').map do |path|
      File.expand_path(path)
    end
  end
end

#pretty_path_from_project(of_file) ⇒ String

Returns relative path to file from root of project.

Parameters:

  • of_file (String)

    absolute path to file

Returns:

  • (String)

    relative path to file from root of project



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

def pretty_path_from_project(of_file)
  Pathname.new(of_file.unicode_normalize).relative_path_from(Pathname.new(project_path)).to_s
end

#project_pathString

Returns:

  • (String)


14
15
16
# File 'lib/epuber/config.rb', line 14

def project_path
  @project_path ||= Dir.pwd.unicode_normalize
end

#release_build_path(target) ⇒ String

Parameters:

Returns:

  • (String)


98
99
100
# File 'lib/epuber/config.rb', line 98

def release_build_path(target)
  File.join(working_path, 'release_build', target.name.to_s)
end

#remove_build_cachesObject



140
141
142
143
144
# 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?Boolean

Returns:

  • (Boolean)


134
135
136
137
138
# 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_lockfileObject

Returns nil.

Returns:

  • nil



79
80
81
82
83
84
# File 'lib/epuber/config.rb', line 79

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) ⇒ String

Parameters:

Returns:

  • (String)


120
121
122
# File 'lib/epuber/config.rb', line 120

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!Object



124
125
126
127
128
129
130
131
132
# File 'lib/epuber/config.rb', line 124

def warn_for_outdated_versions!
  if bookspec_lockfile.epuber_version > Epuber::VERSION
    UI.warning('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`')
  end

  if bookspec_lockfile.bade_version && bookspec_lockfile.bade_version > Bade::VERSION
    UI.warning('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`')
  end
end

#working_pathString

Returns:

  • (String)


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

def working_path
  @working_path ||= File.join(project_path, WORKING_PATH)
end