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,167 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Module < Dsl::Main
4
+
5
+ include Dsl::CodeObject
6
+
7
+ # @option options [Main, Module] :parent (nil)
8
+ def initialize(name, options = {}, &block)
9
+ @name = name
10
+ @code_objects = []
11
+ @access = :public
12
+ @parent = options.fetch(:parent, nil)
13
+ @docstring = Dsl::Docstring.new(nil)
14
+ yield(self) if block
15
+ end
16
+
17
+ attr_reader :name
18
+
19
+ def add(*code_objects)
20
+ code_objects.each do |code_object|
21
+ if Dsl::Method === code_object && code_object.access != @access
22
+ add(AccessControlStatement.new(code_object.access))
23
+ elsif Dsl::AccessControlStatement === code_object
24
+ @access = code_object.access
25
+ end
26
+ super(code_object)
27
+ end
28
+ end
29
+
30
+ def require_statement(path)
31
+ root.require(path)
32
+ end
33
+ alias require require_statement
34
+
35
+ def docstring(docstring = nil)
36
+ @docstring ||= Dsl::Docstring.new
37
+ @docstring.append(docstring) unless docstring.nil?
38
+ @docstring
39
+ end
40
+
41
+ def require_relative(path)
42
+ root.require_relative(path)
43
+ end
44
+
45
+ def constructor(options = {}, &block)
46
+ method(:initialize, options, &block)
47
+ end
48
+
49
+ def attr_accessor(name, options = {}, &block)
50
+ a = Dsl::AttributeAccessor.new(name, options)
51
+ yield(a) if block
52
+ add(a)
53
+ end
54
+
55
+ def autoload(const_name, path)
56
+ @code_objects << AutoloadStatement.new(const_name, path)
57
+ end
58
+
59
+ def attr_reader(name, options = {}, &block)
60
+ a = Dsl::AttributeReader.new(name, options)
61
+ yield(a) if block
62
+ add(a)
63
+ end
64
+
65
+ def attr_writer(name, &block)
66
+ a = Dsl::AttributeWriter.new(name)
67
+ yield(a) if block
68
+ add(a)
69
+ end
70
+
71
+ def eigenclass(&block)
72
+ m = Dsl::Eigenclass.new
73
+ yield(m) if block
74
+ add(m)
75
+ end
76
+
77
+ def lines
78
+ code = []
79
+ code.concat(@docstring.lines)
80
+ code += open_module
81
+ code << :newline if padded?(0)
82
+
83
+ @code_objects.each.with_index do |code_object, n|
84
+ code << code_object.lines
85
+ code << :newline if separator?(n)
86
+ end
87
+
88
+ if @code_objects.empty?
89
+ code[-1] += "; end"
90
+ else
91
+ code += close_module
92
+ end
93
+ code
94
+ end
95
+
96
+ private
97
+
98
+ def open_module
99
+ ["module #{@name}"]
100
+ end
101
+
102
+ def close_module
103
+ ["end"]
104
+ end
105
+
106
+ def padded?(n)
107
+ !@code_objects[n].kind_of?(Dsl::Module) &&
108
+ !(
109
+ @code_objects.all? { |obj| autoload_statement?(obj) } ||
110
+ @code_objects.all? { |obj| mixin?(obj) } ||
111
+ @code_objects.all? { |obj| undocumented_attr_macro?(obj) }
112
+ )
113
+ end
114
+
115
+ def separator?(n)
116
+ if last?(n)
117
+ padded?(@code_objects.size - 1)
118
+ elsif grouped_statements?(n)
119
+ false
120
+ else
121
+ true
122
+ end
123
+ end
124
+
125
+ def last?(n)
126
+ @code_objects.size == n + 1
127
+ end
128
+
129
+ def grouped_statements?(n)
130
+ two_autoloads?(n) ||
131
+ two_mixins?(n) ||
132
+ two_undocumented_attr_macros?(n)
133
+ end
134
+
135
+ def two_autoloads?(n)
136
+ @code_objects[n + 1] &&
137
+ autoload_statement?(@code_objects[n + 1]) &&
138
+ autoload_statement?(@code_objects[n])
139
+ end
140
+
141
+ def two_mixins?(n)
142
+ @code_objects[n + 1] &&
143
+ mixin?(@code_objects[n + 1]) &&
144
+ mixin?(@code_objects[n])
145
+ end
146
+
147
+ def two_undocumented_attr_macros?(n)
148
+ @code_objects[n + 1] &&
149
+ undocumented_attr_macro?(@code_objects[n + 1]) &&
150
+ undocumented_attr_macro?(@code_objects[n])
151
+ end
152
+
153
+ def autoload_statement?(code_object)
154
+ Dsl::AutoloadStatement === code_object
155
+ end
156
+
157
+ def mixin?(code_object)
158
+ Dsl::IncludeStatement === code_object
159
+ end
160
+
161
+ def undocumented_attr_macro?(code_object)
162
+ Dsl::AttributeAccessor === code_object && !code_object.documented?
163
+ end
164
+
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,36 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class OptionTag
4
+
5
+ # @option options [required, String] :name
6
+ # @option options [required, String] :type
7
+ # @option options [String] :param ('options')
8
+ # @option options [Boolean] :required (false)
9
+ # @option options [String, nil] :docstring (nil)
10
+ # @option options [Object] :default
11
+ def initialize(options)
12
+ @name = options.fetch(:name)
13
+ @type = options.fetch(:type)
14
+ @param = options.fetch(:param, 'options')
15
+ @required = options.fetch(:required, false) ? 'required, ' : ''
16
+ @docstring = Dsl::TagDocstring.new(options.fetch(:docstring, nil))
17
+ @default = Dsl::TagDefault.new(options.fetch(:default, nil))
18
+ end
19
+
20
+ def lines
21
+ [first_line] + @docstring.lines
22
+ end
23
+
24
+ private
25
+
26
+ def first_line
27
+ "# @option #{@param} [#{@required}#{@type}] :#{@name}#{yard_default}"
28
+ end
29
+
30
+ def yard_default
31
+ @default.empty? ? '' : " (#{@default})"
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ class Param
4
+
5
+ # @option options [String] :type
6
+ # @option options [Object] :default
7
+ # @option options [String] :docstring
8
+ # @option options [Boolean] :documented (true)
9
+ def initialize(name, options = {})
10
+ @name = name.to_s
11
+ @type = TagType.new(options.fetch(:type, nil))
12
+ @default = TagDefault.new(options.fetch(:default, nil))
13
+ @docstring = TagDocstring.new(options.fetch(:docstring, nil))
14
+ @documented = options.fetch(:documented, true)
15
+ end
16
+
17
+ attr_reader :name, :default
18
+
19
+ def documented?
20
+ !!@documented
21
+ end
22
+
23
+ def tag
24
+ if [@type, @default, @docstring].all?(&:empty?)
25
+ []
26
+ else
27
+ [first_line] + @docstring.lines
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def first_line
34
+ "# @param#{@type} #{@name}#{yard_default}"
35
+ end
36
+
37
+ def yard_default
38
+ @default.empty? ? '' : " (#{@default})"
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,38 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ # @api private
4
+ class ParamList
5
+
6
+ def initialize(params)
7
+ @params = params
8
+ end
9
+
10
+ def signature
11
+ if @params.empty?
12
+ nil
13
+ else
14
+ "(#{@params.map { |p| param_signature(p) }.join(', ')})"
15
+ end
16
+ end
17
+
18
+ def tags
19
+ lines = []
20
+ @params.each do |param|
21
+ lines.concat(param.tag) if param.documented?
22
+ end
23
+ lines
24
+ end
25
+
26
+ private
27
+
28
+ def param_signature(param)
29
+ if param.default.empty?
30
+ param.name
31
+ else
32
+ "#{param.name} = #{param.default}"
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ # @api private
4
+ class ReturnTag
5
+
6
+ # @option options [required, String] :type
7
+ # @option options [String] :docstring
8
+ def initialize(options)
9
+ @type = Dsl::TagType.new(options.fetch(:type))
10
+ @docstring = Dsl::TagDocstring.new(options.fetch(:docstring, nil))
11
+ end
12
+
13
+ def lines
14
+ ["# @return#{@type}"] + @docstring.lines
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ # @api private
4
+ class TagDefault
5
+
6
+ def initialize(default)
7
+ @default = default
8
+ end
9
+
10
+ def to_s
11
+ @default.inspect
12
+ end
13
+
14
+ def empty?
15
+ @default.nil?
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ # @api private
4
+ class TagDocstring
5
+
6
+ def initialize(docstring)
7
+ @lines = docstring.to_s.strip.lines.inject([]) do |lines, line|
8
+ line = line.rstrip
9
+ if line.empty?
10
+ lines << "#"
11
+ else
12
+ lines << "# #{line.rstrip}"
13
+ end
14
+ end
15
+ end
16
+
17
+ # @return Array<String>
18
+ attr_reader :lines
19
+
20
+ # @return [Boolean]
21
+ def empty?
22
+ @lines.empty?
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module AwsSdkCodeGenerator
2
+ module Dsl
3
+ # @api private
4
+ class TagType < String
5
+
6
+ def self.new(type)
7
+ if type
8
+ types = Array(type)
9
+ types = types.map { |t| t.nil? ? 'nil' : t.to_s }
10
+ super(types.empty? ? '' : " [#{types.join(', ')}]")
11
+ else
12
+ super('')
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module AwsSdkCodeGenerator
2
+ module Errors
3
+
4
+ # Raised when generating resource classes that attempt to redefine
5
+ # a method. This can happen when any of the following have the
6
+ # same name:
7
+ #
8
+ # * attributes (as defined in the resource shape members)
9
+ # * actions
10
+ # * has associations
11
+ # * has many associations
12
+ # * waiters
13
+ # * batch actions
14
+ #
15
+ # Additionally this can happen if the resource attempts to
16
+ # redefine methods from Ruby Object.
17
+ class ResourceMethodConflict < RuntimeError
18
+
19
+ # @option options [required, String] :resource_name
20
+ # @option options [required, String] :method_name
21
+ def initialize(options)
22
+ resource_name = options.fetch(:resource_name)
23
+ method_name = options.fetch(:method_name)
24
+ super("#{resource_name} is attempting to redefine ##{method_name}")
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,71 @@
1
+ module AwsSdkCodeGenerator
2
+ class GemBuilder
3
+
4
+ # @param [Hash] options
5
+ # @option options [required, Service] :service
6
+ def initialize(options)
7
+ @options = options
8
+ @service = options.fetch(:service)
9
+ end
10
+
11
+ # @return [Hash]
12
+ attr_reader :options
13
+
14
+ def each(&block)
15
+ Enumerator.new do |y|
16
+ y.yield(gemspec_path, gemspec_file)
17
+ y.yield(features_env_path, features_env_file)
18
+ y.yield(features_step_definitions_path, features_step_definitions_file)
19
+ y.yield(spec_helper_path, spec_helper_file)
20
+ y.yield(version_path, version_file)
21
+ code = CodeBuilder.new(@options)
22
+ code.source_files(prefix: @service.gem_name).each do |path, code|
23
+ y.yield("lib/#{path}", code)
24
+ end
25
+ end.each(&block)
26
+ end
27
+
28
+ private
29
+
30
+ def gemspec_path
31
+ "#{@service.gem_name}.gemspec"
32
+ end
33
+
34
+ def gemspec_file
35
+ Views::Gemspec.new(options).render
36
+ end
37
+
38
+ def features_env_path
39
+ 'features/env.rb'
40
+ end
41
+
42
+ def features_env_file
43
+ Views::Features::Env.new(options).render
44
+ end
45
+
46
+ def features_step_definitions_path
47
+ 'features/step_definitions.rb'
48
+ end
49
+
50
+ def features_step_definitions_file
51
+ Views::Features::StepDefinitions.new(options).render
52
+ end
53
+
54
+ def spec_helper_path
55
+ 'spec/spec_helper.rb'
56
+ end
57
+
58
+ def spec_helper_file
59
+ Views::Spec::SpecHelper.new(options).render
60
+ end
61
+
62
+ def version_path
63
+ 'VERSION'
64
+ end
65
+
66
+ def version_file
67
+ Views::Version.new(options).render
68
+ end
69
+
70
+ end
71
+ end