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.



116
117
118
# File 'lib/epuber/config.rb', line 116

def test
  @test
end

Class Method Details

.instanceEpuber::Config

Singleton

Returns:



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

def self.instance
  @instance ||= new
end

.test?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/epuber/config.rb', line 118

def test?
  test
end

Instance Method Details

#bookspecEpuber::Book

Returns:



54
55
56
57
58
59
60
61
62
63
# File 'lib/epuber/config.rb', line 54

def bookspec
  require_relative 'book'
  @bookspec ||= (
    book = Epuber::Book.from_file(bookspec_path)
    book.finish_toc
    book.validate
    book.freeze
    book
  )
end

#bookspec=(bookspec) ⇒ Epuber::Book

Parameters:

Returns:



69
70
71
# File 'lib/epuber/config.rb', line 69

def bookspec=(bookspec)
  @bookspec = bookspec
end

#bookspec_lockfileEpuber::Lockfile

Returns:



75
76
77
78
79
80
81
# File 'lib/epuber/config.rb', line 75

def bookspec_lockfile
  @bookspec_lockfile ||= (
    lockfile = Lockfile.from_file(bookspec_lockfile_path)
    lockfile.version = Epuber::VERSION
    lockfile
  )
end

#bookspec_lockfile_pathString

Returns:

  • (String)


38
39
40
# File 'lib/epuber/config.rb', line 38

def bookspec_lockfile_path
  "#{bookspec_path}.lock"
end

#bookspec_pathString

Returns:

  • (String)


32
33
34
# File 'lib/epuber/config.rb', line 32

def bookspec_path
  @bookspec_path ||= find_all_bookspecs.first
end

#build_path(target) ⇒ String

Parameters:

Returns:

  • (String)


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

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

#find_all_bookspecsArray<String>

Returns:

  • (Array<String>)


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

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



20
21
22
# File 'lib/epuber/config.rb', line 20

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

#project_pathString

Returns:

  • (String)


12
13
14
# File 'lib/epuber/config.rb', line 12

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

#release_build_path(target) ⇒ String

Parameters:

Returns:

  • (String)


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

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

#save_lockfileObject

Returns nil.

Returns:

  • nil



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

def save_lockfile
  bookspec_lockfile.write_to_file
end

#working_pathString

Returns:

  • (String)


26
27
28
# File 'lib/epuber/config.rb', line 26

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