Class: DomGlancyController

Inherits:
DomGlancyApplicationController show all
Defined in:
app/controllers/dom_glancy_controller.rb

Instance Method Summary collapse

Methods inherited from DomGlancyApplicationController

#get_gem_version

Instance Method Details

#artifactsObject



54
55
56
57
# File 'app/controllers/dom_glancy_controller.rb', line 54

def artifacts
  artifacts_location = File.expand_path(File.join('~', 'Downloads', '*_artifacts.zip'))
  @artifacts = Dir.glob(artifacts_location).map { |f| File.basename(f) }
end

#artifacts_deleteObject



59
60
61
62
63
# File 'app/controllers/dom_glancy_controller.rb', line 59

def artifacts_delete
  artifacts = params[:file].gsub('^', '.')
  FileUtils.rm_rf File.expand_path(File.join('~', 'Downloads', artifacts))
  redirect_to '/dom_glancy/artifacts'
end

#artifacts_expandObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/dom_glancy_controller.rb', line 65

def artifacts_expand
  artifacts = params[:file].gsub('^', '.')
  artifacts = File.expand_path(File.join('~', 'Downloads', artifacts))

  Zip::ZipFile.open(artifacts) do |zip_file|
    zip_file.each do |entry|
      file_destination = generate_unzip_destination(entry.name)
      File.open(file_destination, 'wb') { |file| file.write(zip_file.read(entry)) } if file_destination
    end
  end

  redirect_to dom_glancy_path
end

#blessObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/dom_glancy_controller.rb', line 85

def bless
  blessings = []
  params.each_pair { |k, v| blessings << v if k.start_with?('option_') }

  blessings.each do |blessing|
    base_test_name = blessing
    fnb = DomGlancy::FileNameBuilder.new(base_test_name)

    src_yaml = fnb.current
    dst_yaml = fnb.master

    FileUtils.cp src_yaml, dst_yaml if File.exist?(src_yaml)

    if params['delete_on_bless'] == 'true'
      files_to_remove  = [fnb.diff]
      files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__current_not_master__diff.yaml')
      files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__master_not_current__diff.yaml')
      files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__changed_master__diff.yaml')

      files_to_remove.each { |f| FileUtils.rm_rf f }
    end
  end

  redirect_to dom_glancy_path
end

#clearObject



79
80
81
82
83
# File 'app/controllers/dom_glancy_controller.rb', line 79

def clear
  Dir[File.join(DomGlancy.configuration.diff_file_location, '*.yaml'), File.join(DomGlancy.configuration.diff_file_location, '*.html')].each { |f| FileUtils.rm_rf(f) }
  Dir[File.join(DomGlancy.configuration.current_file_location, '*.yaml')].each { |f| FileUtils.rm_rf(f) }
  redirect_to dom_glancy_path
end

#delete_currentObject



45
46
47
48
49
50
51
52
# File 'app/controllers/dom_glancy_controller.rb', line 45

def delete_current
  test_root = params[:file]
  fnb = DomGlancy::FileNameBuilder.new(test_root)
  src = fnb.current
  FileUtils.rm_rf src

  redirect_to '/dom_glancy/new'
end

#indexObject



6
7
8
9
10
11
12
# File 'app/controllers/dom_glancy_controller.rb', line 6

def index
  @files = if DomGlancy.configuration.diff_file_location
    Dir[File.join(DomGlancy.configuration.diff_file_location, "*_diff.html")].map{|f| File.basename(f)}
  else
    []
  end
end

#make_masterObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/dom_glancy_controller.rb', line 35

def make_master
  test_root = params[:file]
  fnb = DomGlancy::FileNameBuilder.new(test_root)
  src = fnb.current
  dst = fnb.master
  FileUtils.cp src, dst

  redirect_to '/dom_glancy/new'
end

#newObject



28
29
30
31
32
33
# File 'app/controllers/dom_glancy_controller.rb', line 28

def new
  @files_current = Dir[File.join(DomGlancy.configuration.current_file_location, '*.yaml')].map { |f| File.basename(f).gsub('.yaml', '') }
  @files_master  = Dir[File.join(DomGlancy.configuration.master_file_location,  '*.yaml')].map { |f| File.basename(f).gsub('.yaml', '') }

  @extra_files = @files_current.select { |f| !@files_master.include?("#{f}_master")}.sort
end

#path_configObject



25
26
# File 'app/controllers/dom_glancy_controller.rb', line 25

def path_config
end

#showObject



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/dom_glancy_controller.rb', line 14

def show
  @test_root = params[:diff_file].gsub('_diff', '').gsub('.html', '')

  @file_diff            = "#{@test_root}_diff.html"
  @file_set_not_master  = "#{@test_root}__current_not_master__diff.yaml"
  @file_set_not_current = "#{@test_root}__master_not_current__diff.yaml"
  @file_set_changed     = "#{@test_root}__changed_master__diff.yaml"

  @file_diff = "#{@test_root}_diff.html"
end