aws-sdk-code-generator 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aws-sdk-code-generator.rb +91 -0
  3. data/lib/aws-sdk-code-generator/apply_docs.rb +37 -0
  4. data/lib/aws-sdk-code-generator/code_builder.rb +201 -0
  5. data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +23 -0
  6. data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +43 -0
  7. data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +11 -0
  8. data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +11 -0
  9. data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +15 -0
  10. data/lib/aws-sdk-code-generator/dsl/block_param.rb +11 -0
  11. data/lib/aws-sdk-code-generator/dsl/class.rb +27 -0
  12. data/lib/aws-sdk-code-generator/dsl/code_literal.rb +66 -0
  13. data/lib/aws-sdk-code-generator/dsl/code_object.rb +33 -0
  14. data/lib/aws-sdk-code-generator/dsl/docstring.rb +36 -0
  15. data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +15 -0
  16. data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +12 -0
  17. data/lib/aws-sdk-code-generator/dsl/formatter.rb +25 -0
  18. data/lib/aws-sdk-code-generator/dsl/include_statement.rb +17 -0
  19. data/lib/aws-sdk-code-generator/dsl/main.rb +105 -0
  20. data/lib/aws-sdk-code-generator/dsl/method.rb +108 -0
  21. data/lib/aws-sdk-code-generator/dsl/module.rb +167 -0
  22. data/lib/aws-sdk-code-generator/dsl/option_tag.rb +36 -0
  23. data/lib/aws-sdk-code-generator/dsl/param.rb +43 -0
  24. data/lib/aws-sdk-code-generator/dsl/param_list.rb +38 -0
  25. data/lib/aws-sdk-code-generator/dsl/return_tag.rb +19 -0
  26. data/lib/aws-sdk-code-generator/dsl/tag_default.rb +20 -0
  27. data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +27 -0
  28. data/lib/aws-sdk-code-generator/dsl/tag_type.rb +18 -0
  29. data/lib/aws-sdk-code-generator/errors.rb +30 -0
  30. data/lib/aws-sdk-code-generator/gem_builder.rb +71 -0
  31. data/lib/aws-sdk-code-generator/generators/client_api_module.rb +334 -0
  32. data/lib/aws-sdk-code-generator/generators/client_class.rb +389 -0
  33. data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +166 -0
  34. data/lib/aws-sdk-code-generator/generators/errors_module.rb +25 -0
  35. data/lib/aws-sdk-code-generator/generators/resource/action.rb +88 -0
  36. data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +211 -0
  37. data/lib/aws-sdk-code-generator/generators/resource/builder.rb +50 -0
  38. data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +15 -0
  39. data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +49 -0
  40. data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +97 -0
  41. data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +88 -0
  42. data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +180 -0
  43. data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +24 -0
  44. data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +18 -0
  45. data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +49 -0
  46. data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +29 -0
  47. data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +32 -0
  48. data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +101 -0
  49. data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +108 -0
  50. data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +26 -0
  51. data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +28 -0
  52. data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +67 -0
  53. data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +65 -0
  54. data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +68 -0
  55. data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +61 -0
  56. data/lib/aws-sdk-code-generator/generators/resource_class.rb +325 -0
  57. data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +83 -0
  58. data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +42 -0
  59. data/lib/aws-sdk-code-generator/generators/service_documentation.rb +64 -0
  60. data/lib/aws-sdk-code-generator/generators/shared_example.rb +132 -0
  61. data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +95 -0
  62. data/lib/aws-sdk-code-generator/generators/syntax_example.rb +169 -0
  63. data/lib/aws-sdk-code-generator/generators/types_module.rb +52 -0
  64. data/lib/aws-sdk-code-generator/generators/waiter_class.rb +62 -0
  65. data/lib/aws-sdk-code-generator/generators/waiters_module.rb +20 -0
  66. data/lib/aws-sdk-code-generator/hash_formatter.rb +122 -0
  67. data/lib/aws-sdk-code-generator/helper.rb +215 -0
  68. data/lib/aws-sdk-code-generator/service.rb +126 -0
  69. data/lib/aws-sdk-code-generator/underscore.rb +45 -0
  70. data/lib/aws-sdk-code-generator/view.rb +23 -0
  71. data/lib/aws-sdk-code-generator/views.rb +3 -0
  72. data/lib/aws-sdk-code-generator/views/features/env.rb +24 -0
  73. data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +20 -0
  74. data/lib/aws-sdk-code-generator/views/gemspec.rb +41 -0
  75. data/lib/aws-sdk-code-generator/views/service_module.rb +85 -0
  76. data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +24 -0
  77. data/lib/aws-sdk-code-generator/views/version.rb +16 -0
  78. metadata +120 -0
@@ -0,0 +1,11 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class BlockParam < Param
4
+
5
+ def initialize(options = {})
6
+ super('&block')
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Class < Dsl::Module
4
+
5
+ # @option options [String, nil] :extends (nil)
6
+ def initialize(name, options = {}, &block)
7
+ super(name, options, &block)
8
+ @extends = options.fetch(:extends, nil)
9
+ end
10
+
11
+ def open_module
12
+ lines = ["class #{@name}"]
13
+ if @extends
14
+ extends = @extends.lines.to_a
15
+ lines[-1] = "#{lines[-1]} < #{extends[0].rstrip}"
16
+ extends[1..-1].each do |line|
17
+ lines << line.rstrip
18
+ end
19
+ lines
20
+ else
21
+ ["class #{@name}"]
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,66 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class CodeLiteral
4
+
5
+ include Dsl::CodeObject
6
+
7
+ # @param [String] code
8
+ # @option options [Integer] :nesting (0)
9
+ def initialize(code = nil, options = {}, &block)
10
+ @code_objects = []
11
+ @nesting = options.fetch(:nesting, 0)
12
+ append(code) if code
13
+ yield(self) if block
14
+ end
15
+
16
+ attr_accessor :nesting
17
+
18
+ # @param [String, CodeLiteral]
19
+ def <<(code)
20
+ if CodeLiteral === code || String === code
21
+ @code_objects << [@nesting, code]
22
+ else
23
+ msg = "expected String or CodeLiteral, got #{code.class}"
24
+ raise ArgumentError, msg
25
+ end
26
+ end
27
+ alias :append :<<
28
+
29
+ def newline
30
+ @code_objects << [@nesting, :newline]
31
+ end
32
+
33
+ def indent(code = nil, &block)
34
+ @nesting += 1
35
+ code = CodeLiteral.new(code) unless CodeLiteral === code
36
+ append(code)
37
+ yield(code) if block
38
+ @nesting -= 1
39
+ code
40
+ end
41
+
42
+ def lines(pad = '')
43
+ lines = []
44
+ @code_objects.each do |i, code_obj|
45
+ case code_obj
46
+ when :newline
47
+ lines << :newline
48
+ when String
49
+ code_obj.lines.each do |line|
50
+ line = line.rstrip
51
+ if line == ''
52
+ lines << :newline
53
+ else
54
+ lines << "#{pad}#{' ' * i}#{line}"
55
+ end
56
+ end
57
+ when CodeLiteral
58
+ lines.concat(code_obj.lines(pad + (' ' * i)))
59
+ end
60
+ end
61
+ lines
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,33 @@
1
+ require 'set'
2
+
3
+ module AwsSdkCodeGenerator
4
+ module Dsl
5
+ # @api private
6
+ module CodeObject
7
+
8
+ def to_s
9
+ format(lines)
10
+ end
11
+
12
+ private
13
+
14
+ def underscore(str)
15
+ Underscore.underscore(str)
16
+ end
17
+
18
+ def format(lines, nesting = 0)
19
+ i = ' ' * nesting
20
+ lines.inject([]) do |code, obj|
21
+ case obj
22
+ when :newline then code << "\n"
23
+ when String then code << "#{i}#{obj}\n"
24
+ when CodeObject then code.concat(obj.lines)
25
+ when Array, Enumerator then code << format(obj, nesting + 1)
26
+ else raise ArgumentError, "got #{obj.class}"
27
+ end
28
+ end.join
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ # @api private
4
+ class Docstring
5
+
6
+ include Dsl::CodeObject
7
+
8
+ # @param [String, nil]
9
+ def initialize(docstring = nil, &block)
10
+ @lines = []
11
+ append(docstring)
12
+ yield(self) if block
13
+ end
14
+
15
+ def append(docstring)
16
+ @lines.concat(docstring.to_s.rstrip.lines.map do |line|
17
+ if line == "\n"
18
+ "#"
19
+ else
20
+ "# #{line.rstrip}"
21
+ end
22
+ end)
23
+ end
24
+ alias :<< :append
25
+
26
+ # @return [Array<String>]
27
+ attr_reader :lines
28
+
29
+ # @return [Boolean]
30
+ def empty?
31
+ @lines.empty?
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Eigenclass < Dsl::Module
4
+
5
+ def initialize(&block)
6
+ super('self', &block)
7
+ end
8
+
9
+ def open_module
10
+ ["class << self"]
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+
4
+ class ExtendStatement < IncludeStatement
5
+
6
+ def lines
7
+ ["extend #{@module_name}"]
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Formatter
4
+
5
+ def initialize
6
+ @indent = ' '
7
+ end
8
+
9
+ def format(lines, nesting:0)
10
+ i = @indent * nesting
11
+ lines.inject([]) do |code, section|
12
+ case section
13
+ when "\n" then code << "\n" # do not indent blank lines
14
+ when CodeObject then code.concat(section.lines)
15
+ when String then code << "#{i}#{section}"
16
+ when Array then code << format(section, nesting:nesting + 1)
17
+ else
18
+ raise ArgumentError, "got #{section.class}"
19
+ end
20
+ end.join
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class IncludeStatement
4
+
5
+ include Dsl::CodeObject
6
+
7
+ def initialize(module_name)
8
+ @module_name = module_name
9
+ end
10
+
11
+ def lines
12
+ ["include #{@module_name}"]
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,105 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Main
4
+
5
+ include Dsl::CodeObject
6
+
7
+ # @option options [Main, Module] :parent (nil)
8
+ def initialize(options = {}, &block)
9
+ @comments = Docstring.new(nil)
10
+ @top_content = []
11
+ @code_objects = []
12
+ @parent = options.fetch(:parent, nil)
13
+ yield(self) if block
14
+ end
15
+
16
+ # @return [nil, CodeObject]
17
+ attr_accessor :parent
18
+
19
+ # @return [nil, CodeObject]
20
+ def root
21
+ root = self
22
+ root = root.parent while root && root.parent
23
+ root
24
+ end
25
+
26
+ def add(*code_objects)
27
+ code_objects.each do |code_obj|
28
+ @code_objects << code_obj unless code_obj.nil?
29
+ end
30
+ end
31
+
32
+ def code(code = nil, &block)
33
+ @code_objects << CodeLiteral.new(code, &block)
34
+ end
35
+
36
+ def comments(docstring)
37
+ @comments = Docstring.new(docstring)
38
+ end
39
+
40
+ def include_module(module_name)
41
+ add(IncludeStatement.new(module_name))
42
+ end
43
+ alias :include :include_module
44
+
45
+ def extend_module(module_name)
46
+ add(ExtendStatement.new(module_name))
47
+ end
48
+ alias :extend :extend_module
49
+
50
+ def require_statement(path)
51
+ @top_content << "require '#{path}'"
52
+ end
53
+ alias require require_statement
54
+
55
+ # Allows inserting top-of document content.
56
+ def top(string)
57
+ root.instance_variable_get("@top_content") << string
58
+ end
59
+
60
+ def require_relative(path)
61
+ @top_content << "require_relative '#{path}'"
62
+ end
63
+
64
+ def method(name, options = {}, &block)
65
+ m = Dsl::Method.new(name, options)
66
+ yield(m) if block
67
+ add(m)
68
+ end
69
+
70
+ def module(name, &block)
71
+ m = Dsl::Module.new(name, parent: self)
72
+ yield(m) if block
73
+ add(m)
74
+ m
75
+ end
76
+
77
+ def class(name, options = {}, &block)
78
+ c = Dsl::Class.new(name, options.merge(parent: self))
79
+ yield(c) if block
80
+ add(c)
81
+ c
82
+ end
83
+
84
+ def lines
85
+
86
+ lines = []
87
+
88
+ lines.concat(@comments.lines)
89
+ lines << :newline unless @comments.empty?
90
+
91
+ @top_content.each do |statement|
92
+ lines << statement
93
+ end
94
+ lines << :newline unless @top_content.empty?
95
+
96
+ @code_objects.each.with_index do |code_obj, n|
97
+ lines.concat(code_obj.lines)
98
+ lines << :newline unless n == @code_objects.size - 1
99
+ end
100
+ lines
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,108 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Method
4
+
5
+ include Dsl::CodeObject
6
+
7
+ # @option options [Symbol] :access (:public)
8
+ # @option options [String, nil] :docstring (nil)
9
+ def initialize(name, options = {}, &block)
10
+ @name = name.to_s
11
+ @access = options.fetch(:access, :public)
12
+ @code_objects = []
13
+ @params = []
14
+ @option_tags = []
15
+ @return_tags = []
16
+ @aliases = []
17
+ @docstring = Dsl::Docstring.new(options.fetch(:docstring, nil))
18
+ @api_private = options.fetch(:api_private, false)
19
+ yield(self) if block
20
+ end
21
+
22
+ attr_reader :name
23
+
24
+ attr_reader :access
25
+
26
+ attr_reader :aliases
27
+
28
+ def param(name, options = {})
29
+ @params << Param.new(name, options)
30
+ end
31
+
32
+ def option(options)
33
+ @option_tags << OptionTag.new(options)
34
+ end
35
+
36
+ def returns(type, options = {})
37
+ @return_tags << ReturnTag.new(options.merge(type:type))
38
+ end
39
+
40
+ def add(*code_objects)
41
+ @code_objects.concat(code_objects)
42
+ end
43
+
44
+ def code(code = nil, &block)
45
+ @code_objects << CodeLiteral.new(code, &block)
46
+ end
47
+
48
+ def empty?
49
+ @code_objects.empty?
50
+ end
51
+
52
+ def docstring(docstring = nil, &block)
53
+ @docstring.append(docstring)
54
+ yield(@docstring) if block
55
+ @docstring
56
+ end
57
+
58
+ def block_param
59
+ @params << BlockParam.new
60
+ end
61
+
62
+ def alias_as(other_name)
63
+ @aliases << other_name.to_s
64
+ end
65
+
66
+ def lines
67
+ code = []
68
+ code.concat(yard_docs)
69
+ code << method_signature
70
+ code << method_body
71
+ code << method_end
72
+ code.concat(@aliases.map { |a| "alias :#{a} :#{@name}" })
73
+ code
74
+ end
75
+
76
+ private
77
+
78
+ def yard_docs
79
+ docs = []
80
+ docs.concat(@docstring.lines)
81
+ tags = []
82
+ tags.concat(ParamList.new(@params).tags)
83
+ tags.concat(@option_tags)
84
+ tags.concat(@return_tags)
85
+ tags << "# @api private" if @api_private
86
+ tags.each.with_index do |tag, n|
87
+ docs.concat(tag.lines.to_a)
88
+ end
89
+ docs.compact
90
+ end
91
+
92
+ def method_signature
93
+ "def #{@name}#{ParamList.new(@params).signature}"
94
+ end
95
+
96
+ def method_body
97
+ @code_objects.inject([]) do |lines, code_obj|
98
+ lines.concat(code_obj.lines)
99
+ end
100
+ end
101
+
102
+ def method_end
103
+ "end"
104
+ end
105
+
106
+ end
107
+ end
108
+ end