Class: Epuber::Config
- Inherits:
-
Object
- Object
- Epuber::Config
- Defined in:
- lib/epuber/config.rb
Constant Summary collapse
- WORKING_PATH =
'.epuber'
Class Attribute Summary collapse
-
.test ⇒ Object
Returns the value of attribute test.
Instance Attribute Summary collapse
Class Method Summary collapse
- .clear_instance! ⇒ Object
-
.instance ⇒ Epuber::Config
Singleton.
- .load_bookspec(path, frozen: true) ⇒ Epuber::Book
- .test? ⇒ Boolean
Instance Method Summary collapse
- #bookspec_lockfile ⇒ Epuber::Lockfile
- #bookspec_lockfile_path ⇒ String
- #bookspec_path ⇒ String
- #build_cache_path(cache_name) ⇒ String
- #build_path(target) ⇒ String
- #file_stat_database_path ⇒ String
- #find_all_bookspecs ⇒ Array<String>
-
#pretty_path_from_project(of_file) ⇒ String
Relative path to file from root of project.
- #project_path ⇒ String
- #release_build_path(target) ⇒ String
- #remove_build_caches ⇒ Object
- #same_version_as_last_run? ⇒ Boolean
-
#save_lockfile ⇒ Object
Nil.
- #target_file_stat_database_path(target) ⇒ String
- #warn_for_outdated_versions! ⇒ Object
- #working_path ⇒ String
Class Attribute Details
.test ⇒ Object
Returns the value of attribute test.
154 155 156 |
# File 'lib/epuber/config.rb', line 154 def test @test end |
Instance Attribute Details
#bookspec ⇒ Epuber::Book
55 56 57 |
# File 'lib/epuber/config.rb', line 55 def bookspec @bookspec ||= self.class.load_bookspec(bookspec_path) end |
#release_build ⇒ Boolean
67 68 69 |
# File 'lib/epuber/config.rb', line 67 def release_build @release_build end |
Class Method Details
.clear_instance! ⇒ Object
168 169 170 |
# File 'lib/epuber/config.rb', line 168 def clear_instance! @instance = nil end |
.instance ⇒ Epuber::Config
Singleton
164 165 166 |
# File 'lib/epuber/config.rb', line 164 def instance @instance ||= new end |
.load_bookspec(path, frozen: true) ⇒ Epuber::Book
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/epuber/config.rb', line 174 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
156 157 158 |
# File 'lib/epuber/config.rb', line 156 def test? test end |
Instance Method Details
#bookspec_lockfile ⇒ Epuber::Lockfile
71 72 73 74 75 76 |
# File 'lib/epuber/config.rb', line 71 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 ⇒ String
39 40 41 |
# File 'lib/epuber/config.rb', line 39 def bookspec_lockfile_path "#{bookspec_path}.lock" end |
#bookspec_path ⇒ String
33 34 35 |
# File 'lib/epuber/config.rb', line 33 def bookspec_path @bookspec_path ||= find_all_bookspecs.first end |
#build_cache_path(cache_name) ⇒ String
107 108 109 |
# File 'lib/epuber/config.rb', line 107 def build_cache_path(cache_name) File.join(working_path, 'build_cache', cache_name) end |
#build_path(target) ⇒ String
91 92 93 |
# File 'lib/epuber/config.rb', line 91 def build_path(target) File.join(working_path, 'build', target.name.to_s) end |
#file_stat_database_path ⇒ String
113 114 115 |
# File 'lib/epuber/config.rb', line 113 def file_stat_database_path File.join(working_path, 'metadata', 'source_file_stats.yml') end |
#find_all_bookspecs ⇒ Array<String>
45 46 47 48 49 50 51 |
# File 'lib/epuber/config.rb', line 45 def find_all_bookspecs Dir.chdir(project_path) do Dir.glob('*.bookspec').map do |path| File.(path) end end end |
#pretty_path_from_project(of_file) ⇒ String
Returns relative path to file from root of project.
21 22 23 |
# File 'lib/epuber/config.rb', line 21 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 ⇒ String
13 14 15 |
# File 'lib/epuber/config.rb', line 13 def project_path @project_path ||= Dir.pwd.unicode_normalize end |
#release_build_path(target) ⇒ String
99 100 101 |
# File 'lib/epuber/config.rb', line 99 def release_build_path(target) File.join(working_path, 'release_build', target.name.to_s) end |
#remove_build_caches ⇒ Object
145 146 147 148 149 |
# File 'lib/epuber/config.rb', line 145 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
139 140 141 142 143 |
# File 'lib/epuber/config.rb', line 139 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 ⇒ Object
Returns nil.
80 81 82 83 84 85 |
# File 'lib/epuber/config.rb', line 80 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
121 122 123 |
# File 'lib/epuber/config.rb', line 121 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
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/epuber/config.rb', line 125 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 ⇒ String
27 28 29 |
# File 'lib/epuber/config.rb', line 27 def working_path @working_path ||= File.join(project_path, WORKING_PATH) end |