Class: Awspec::Generator::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/awspec/generator/template.rb

Class Method Summary collapse

Class Method Details

.file_check_and_puts(path, content) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/awspec/generator/template.rb', line 89

def self.file_check_and_puts(path, content)
  if File.exist? @root_path + path
    $stderr.puts "!! #{path} already exists"
  else
    File.open(@root_path + path, 'w') do |f|
      f.puts content
    end
    puts " + #{path}"
  end
end

.generate(type) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/awspec/generator/template.rb', line 3

def self.generate(type)
  @type = type
  @root_path = File.dirname(__FILE__) + '/../../../'
  generate_stub
  generate_type
  generate_type_spec
  generate_generator_doc
  put_message
end

.generate_generator_docObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/awspec/generator/template.rb', line 54

def self.generate_generator_doc
  path = 'lib/awspec/generator/doc/type/' + @type.underscore + '.rb'
  full_path = @root_path + path
  content = "module Awspec::Generator\n  module Doc\nmodule Type\n  class \#{@type.camelize} < Base\n    def initialize\n      super\n      @type_name = '\#{@type.camelize}'\n      @type = Awspec::Type::\#{@type.camelize}.new('my-\#{@type.underscore.tr('_', '-')}')\n      @ret = @type.resource\n      @matchers = []\n      @ignore_matchers = []\n      @describes = []\n    end\n  end\nend\n  end\nend\n"
  self.file_check_and_puts(path, content)
end

.generate_stubObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/awspec/generator/template.rb', line 29

def self.generate_stub
  path = 'lib/awspec/stub/' + @type.underscore + '.rb'
  full_path = @root_path + path
  content = "# Aws.config[:ec2] = {\n#   stub_responses: true\n# }\n"
  self.file_check_and_puts(path, content)
end

.generate_typeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/awspec/generator/template.rb', line 13

def self.generate_type
  path = 'lib/awspec/type/' + @type.underscore + '.rb'
  full_path = @root_path + path
  content = "module Awspec::Type\n  class \#{@type.camelize} < Base\ndef initialize(id)\n  super\n  # @id = # @FIXME\nend\n  end\nend\n"
  self.file_check_and_puts(path, content)
end

.generate_type_specObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/awspec/generator/template.rb', line 40

def self.generate_type_spec
  path = 'spec/type/' + @type.underscore + '_spec.rb'
  full_path = @root_path + path
  content = "require 'spec_helper'\nAwspec::Stub.load '\#{@type.underscore}'\n\ndescribe \#{@type.underscore}('my-\#{@type.underscore.tr('_', '-')}') do\n  it { should exist }\nend\n"
  self.file_check_and_puts(path, content)
end

.put_messageObject



79
80
81
82
83
84
85
86
87
# File 'lib/awspec/generator/template.rb', line 79

def self.put_message
  content = "\nGenarate \#{@type.camelize} template files.\n\n* !! AND add '\#{@type.underscore}' to Awspec::Helper::Type::TYPES in awspec/lib/helper/type.rb *\n\n"
end