Class: Adva::Static::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/adva/static/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Setup

Returns a new instance of Setup.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/adva/static/setup.rb', line 8

def initialize(options)
  @app    = options[:app] || Rails.application
  @root   = Pathname.new(options[:root] || Dir.pwd)
  @source = root.join(options[:source]  || 'import')
  @target = root.join(options[:target]  || 'export')
  @remote = options[:remote]
  @host   = options[:host]  || 'example.org'
  @title  = options[:title] || host

  Adva.out = StringIO.new('')
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def app
  @app
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def host
  @host
end

#remoteObject (readonly)

Returns the value of attribute remote.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def remote
  @remote
end

#rootObject (readonly)

Returns the value of attribute root.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def root
  @root
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def target
  @target
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/adva/static/setup.rb', line 6

def title
  @title
end

Instance Method Details

#initial_import_and_exportObject



34
35
36
37
# File 'lib/adva/static/setup.rb', line 34

def initial_import_and_export
  Import.new(:source => source).run
  Export.new(app, :target => target).run
end

#runObject



20
21
22
23
24
25
# File 'lib/adva/static/setup.rb', line 20

def run
  setup_directories
  initial_import_and_export
  setup_source_repository
  setup_export_repository
end

#setup_directoriesObject



27
28
29
30
31
32
# File 'lib/adva/static/setup.rb', line 27

def setup_directories
  source.mkdir rescue Errno::EEXIST
  target.mkdir rescue Errno::EEXIST
  site = source.join('site.yml')
  File.open(site, 'w+') { |f| f.write(YAML.dump(:host => host, :title => title)) } unless site.exist?
end

#setup_export_repositoryObject



54
55
56
57
58
59
60
61
62
# File 'lib/adva/static/setup.rb', line 54

def setup_export_repository
  root.join('export/.git').rmtree rescue Errno::ENOENT

  Dir.chdir(target) do
    init_repository
    commit("#{host} export")
    add_remote('master') if remote
  end
end

#setup_source_repositoryObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/adva/static/setup.rb', line 39

def setup_source_repository
  root.join('.gitignore').rmtree rescue Errno::ENOENT
  root.join('.git').rmtree rescue Errno::ENOENT

  File.open(root.join('.gitignore'), 'w+') { |f| f.write('export') }

  Dir.chdir(root) do
    init_repository
    commit("#{host} source")
    checkout_branch('source')
    delete_branch('master')
    add_remote('source') if remote
  end
end