Class: Awspec::Generator::Template
- Inherits:
-
Object
- Object
- Awspec::Generator::Template
- Defined in:
- lib/awspec/generator/template.rb
Overview
rubocop:disable Metrics/ClassLength
Class Method Summary collapse
- .file_check_and_puts(path, content) ⇒ Object
- .generate(type) ⇒ Object
- .generate_account_attribute(type) ⇒ Object
- .generate_account_attribute_generator_doc ⇒ Object
- .generate_generator_doc ⇒ Object
- .generate_resource_type_doc ⇒ Object
- .generate_stub ⇒ Object
- .generate_type ⇒ Object
- .generate_type_spec ⇒ Object
- .put_message ⇒ Object
Class Method Details
.file_check_and_puts(path, content) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/awspec/generator/template.rb', line 135 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
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/awspec/generator/template.rb', line 4 def self.generate(type) @type = type @account_attribute = false @root_path = File.dirname(__FILE__) + '/../../../' generate_stub generate_type generate_type_spec generate_generator_doc generate_resource_type_doc end |
.generate_account_attribute(type) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/awspec/generator/template.rb', line 16 def self.generate_account_attribute(type) @type = type @account_attribute = true @root_path = File.dirname(__FILE__) + '/../../../' generate_type generate_account_attribute_generator_doc generate_resource_type_doc end |
.generate_account_attribute_generator_doc ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/awspec/generator/template.rb', line 92 def self.generate_account_attribute_generator_doc path = 'lib/awspec/generator/doc/type/' + @type.underscore + '.rb' content = "module Awspec::Generator\n module Doc\nmodule Type\n class \#{@type.camelize} < AccountAttributeBase\n def initialize\n super\n @type_name = '\#{@type.camelize}'\n @type = Awspec::Type::\#{@type.camelize}.new\n @ret = @type.resource_via_client\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_generator_doc ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/awspec/generator/template.rb', line 68 def self.generate_generator_doc path = 'lib/awspec/generator/doc/type/' + @type.underscore + '.rb' 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_via_client\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_resource_type_doc ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/awspec/generator/template.rb', line 116 def self.generate_resource_type_doc path = 'doc/_resource_types/' + @type.underscore + '.md' content = "# exist\n" self.file_check_and_puts(path, content) end |
.generate_stub ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/awspec/generator/template.rb', line 45 def self.generate_stub path = 'lib/awspec/stub/' + @type.underscore + '.rb' content = "# Aws.config[:ec2] = {\n# stub_responses: true\n# }\n" self.file_check_and_puts(path, content) end |
.generate_type ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/awspec/generator/template.rb', line 26 def self.generate_type path = 'lib/awspec/type/' + @type.underscore + '.rb' base = @account_attribute ? 'AccountAttributeBase' : 'ResourceBase' content = "module Awspec::Type\n class \#{@type.camelize} < \#{base}\ndef resource_via_client\n @resource_via_client ||= # FIXME\nend\n\ndef id\n @id ||= # FIXME\nend\n end\nend\n" self.file_check_and_puts(path, content) end |
.generate_type_spec ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/awspec/generator/template.rb', line 55 def self.generate_type_spec path = 'spec/type/' + @type.underscore + '_spec.rb' 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_message ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/awspec/generator/template.rb', line 124 def self. content = "\nGenerate \#{@type.camelize} template files.\n\n* !! AND add '\#{@type.underscore}' to Awspec::Helper::Type::TYPES in lib/awspec/helper/type.rb *\n* !! AND add '\#{@type.underscore}' client to lib/awspec/helper/finder.rb *\n\n" end |