Class: Quik::Builder

Inherits:
Object
  • Object
show all
Includes:
Wizard
Defined in:
lib/quik/builder.rb

Constant Summary

Constants included from Wizard

Wizard::NO_REGEX, Wizard::YES_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Wizard

#ask, #getstr, #no?, #say, #select, #yes?

Constructor Details

#initialize(opts = {}) ⇒ Builder

Returns a new instance of Builder.



21
22
23
24
25
26
27
# File 'lib/quik/builder.rb', line 21

def initialize( opts={} )
  puts "==> starting new Quik script with options #{opts.inspect}; lets go"

  @test       = opts[:dry_run] || opts[:test] || false
  @output_dir = opts[:o] || '.'
  @pak        = nil   ## for now reference last template pack (in future support many - why?? why not??)
end

Class Method Details

.load(code, opts = {}) ⇒ Object



12
13
14
15
16
# File 'lib/quik/builder.rb', line 12

def self.load( code, opts={} )
  builder = Builder.new( opts )
  builder.instance_eval( code )
  builder
end

.load_file(path, opts = {}) ⇒ Object



7
8
9
10
# File 'lib/quik/builder.rb', line 7

def self.load_file( path, opts={} )
  code = File.open( path, 'r:utf-8' ) { |f| f.read }
  self.load( code, opts )
end

Instance Method Details

#config(opts = {}) {|c| ... } ⇒ Object

Yields:

  • (c)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/quik/builder.rb', line 58

def config( opts={} )
  puts "==> handle config block"
  c = OpenConfig.new
  yield( c )
  ## pp c
  h = c.to_h

  pp h

  ##
  # check for name
  ##  required for output
  ##  if no name
  ##  use ./ working folder for output!!!

  name = h['name']

  if name.nil? || name.empty?
    fail 'sorry; for now name is required for output folder'
  end

  if test?
    ## do nothing; dry run
  else
    if @pak
      unzip_dir = "./#{name}"
      ## step 1: unzip templates
      @pak.unzip( unzip_dir )
      ## step 2: merge templates (using hash/config settings)
      m = Quik::Merger.new
      m.merge( unzip_dir, h )
    end
  end
end

#install_template(name, opts = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/quik/builder.rb', line 39

def install_template( name, opts= {} )
  puts "==> handle install_template >#{name}< with options #{opts.inspect}"

  ## note for now assume name is key
  ##   e.g. always downcase (e.g. Gem => gem)
  key = name.downcase

  if test?
    # do nothing; dry run
  else
    @pak = Package.new( key )

    puts "GET #{@pak.remote_zip_url}".bold.green   ## output network access in green bold
    @pak.download
    ##  pak.unzip( "#{@output_dir}/#{key}" )
  end
end

#output_dirObject

ouptput (root) dir (defaults to . e.g. working folder)



31
# File 'lib/quik/builder.rb', line 31

def output_dir() @output_dir; end

#test?Boolean

“global” builder options

Returns:

  • (Boolean)


30
# File 'lib/quik/builder.rb', line 30

def test?()      @test;       end

#use(name, opts = {}) ⇒ Object

short alias for install_template



35
36
37
# File 'lib/quik/builder.rb', line 35

def use( name, opts={} )  ## short alias for install_template
  install_template( name, opts )
end