Class: Bookfile::Bookfile

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/bookfile/bookfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBookfile

Returns a new instance of Bookfile.



31
32
33
34
35
# File 'lib/bookfile/bookfile.rb', line 31

def initialize
  @packages  = []    # only allow single package  - why, why not??

  @databases = []    # only allow single database - why, why not??

  @books     = []    # only allow single book     - why, why not??

end

Instance Attribute Details

#booksObject (readonly)

Returns the value of attribute books.



29
30
31
# File 'lib/bookfile/bookfile.rb', line 29

def books
  @books
end

#databasesObject (readonly)

Returns the value of attribute databases.



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

def databases
  @databases
end

#packagesObject (readonly)

Returns the value of attribute packages.



27
28
29
# File 'lib/bookfile/bookfile.rb', line 27

def packages
  @packages
end

Class Method Details

.load(code) ⇒ Object

another convenience method - use like Bookfile.load()



18
19
20
21
22
23
# File 'lib/bookfile/bookfile.rb', line 18

def self.load( code )
  # Note: return datafile (of course, NOT the builder)

  # if you want a builder use Bookfile::Builder ;-)

  builder = Builder.load( code )
  builder.bookfile
end

.load_file(path = './Bookfile') ⇒ Object

convenience method - use like Bookfile.load_file()



10
11
12
13
14
15
# File 'lib/bookfile/bookfile.rb', line 10

def self.load_file( path='./Bookfile' )
  # Note: return datafile (of course, NOT the builder)

  # if you want a builder use Bookfile::Builder ;-)

  builder = Builder.load_file( path )
  builder.bookfile
end

Instance Method Details

#build(unzip_dir) ⇒ Object



86
87
88
89
90
91
# File 'lib/bookfile/bookfile.rb', line 86

def build( unzip_dir )
  puts "[bookfile] build books"
  @books.each do |book|
    book.build( unzip_dir )
  end
end

#connectObject

def setup

  puts "[bookfile] setup database connections n models"
  @databases.each do |database|
    database.setup
  end
end


68
69
70
71
72
73
# File 'lib/bookfile/bookfile.rb', line 68

def connect
  puts "[bookfile] connect to database(s)"
  @databases.each do |database|
    database.connect
  end
end

#downloadObject



38
39
40
41
42
43
# File 'lib/bookfile/bookfile.rb', line 38

def download
  puts "[bookfile] dowload book packages"
  @packages.each do |package|
    package.download
  end
end

#dumpObject



95
96
97
98
99
100
101
# File 'lib/bookfile/bookfile.rb', line 95

def dump
##    ## for debugging dump datasets (note: will/might also check if zip exits)

##    logger.info( "[datafile] dump datasets (for debugging)" )

##    @datasets.each do |dataset|

##      dataset.dump()

##    end

end

#prepare(unzip_dir) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/bookfile/bookfile.rb', line 76

def prepare( unzip_dir )
  @databases.each do |database|
    database.prepare    ## require models and include in builder/page ctx

  end
  @packages.each do |package|
    package.prepare( unzip_dir )     ## require helpers and include in builder/page ctx

  end
end

#unzip(unzip_dir) ⇒ Object

todo/fix - add unzip_dir as an option/config to constructor - why, why not??

location needs to get (re)used in prepare too
for now pass along unzip_dir again ???


49
50
51
52
53
54
55
56
# File 'lib/bookfile/bookfile.rb', line 49

def unzip( unzip_dir )
  puts "[bookfile] unzip book packages"
  ### fix: for multiple packages use a number?? - how to make path unique

  ##     for now is ./book 

  @packages.each do |package|
    package.unzip( unzip_dir )
  end
end