harbourmaster 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9db5aee903e9de879c9533ba8682387e34be4b0
4
+ data.tar.gz: 2e628fbb6d88224da55360922507d545bd92c035
5
+ SHA512:
6
+ metadata.gz: 9004d32100873aeea63ec0b5920f1bb72ef4cebb1cb899b7c2eb48210accca05674864bac3915b3d211663121d24c4db276c2358e723aab3782cb54800e4c8ed
7
+ data.tar.gz: d9fcc8c8f5b8a43c9c4ce78a1eb2e3938934a65bef6f4a14c96411cbf5ef1753ce89f394ba472ac49b1797b131b7380529cb5c4fa5e63beb4a32e6ae3d62c281
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Isaac Norman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Harbourmaster
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Harbourmaster'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,21 @@
1
+ module Harbourmaster
2
+ class ControllerGenerator < Rails::Generators::NamedBase
3
+ desc 'Used to create a documented API controller'
4
+ argument :api_base_route, type: :string, default: "app/controllers/api"
5
+ class_option :permit_params, type: :boolean, desc: "When included will generate a permitted_params method in the controller"
6
+ class_option :actions, type: :array, aliases: '-a', desc: "List of controller actions to generate"
7
+ source_root File.expand_path('../templates', __FILE__)\
8
+
9
+ def create_controller_file
10
+ template 'controller.rb', "#{api_base_route}/#{plural_name}_controller.rb"
11
+ end
12
+
13
+ def create_acceptance_tests
14
+ template 'acceptance_tests.rb', "spec/acceptance/#{plural_name}_spec.rb" if options['actions']
15
+ end
16
+
17
+ def create_serializer
18
+ template 'serializer.rb', "app/serializers/#{name.underscore}_serializer.rb"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,76 @@
1
+ require "rails_helper"
2
+ require "rspec_api_documentation/dsl"
3
+
4
+ resource "<%= name.camelize %>" do
5
+ before do
6
+ @<%= name.underscore -%> = create(:<%= name.underscore -%>)
7
+ end
8
+
9
+ <%- if options["actions"].include? "index" -%>
10
+ # get INDEX docs
11
+ get "/<%= plural_name -%>" do
12
+
13
+ example "Listing <%= plural_name -%>" do
14
+ do_request
15
+
16
+ expect(status).to eq 200
17
+ end
18
+
19
+ parameter :name, "Name of the last record on the previous page", required: false, scope: :from
20
+ let(:name) { "b" }
21
+ example "Listing <%= plural_name -%> from the letter B (pagination)" do
22
+ explanation "This uses the paginative gem for pagination by showing only the records after the record you pass in."
23
+
24
+ expect(params).to eq({ from: { name: "b" } }.as_json)
25
+ end
26
+ end
27
+ <%- end -%>
28
+
29
+ <%- if options["actions"].include? "show" -%>
30
+ # get SHOW docs
31
+ get "/<%= plural_name -%>/:id" do
32
+ let(:id) { @<%= name.underscore -%>.id }
33
+
34
+ example "Get a specific <%= name.underscore %>" do
35
+ do_request
36
+
37
+ expect(status).to eq 200
38
+ end
39
+ end
40
+ <%- end -%>
41
+
42
+ <%- if options["actions"].include? "create" -%>
43
+ # post CREATE docs
44
+ post "/<%= plural_name -%>" do
45
+ example "Creating a <%= name.underscore %>" do
46
+ do_request(<%= name.underscore %>: @<%= name.underscore -%>.attributes.except("id", "created_at").as_json)
47
+
48
+ expect(status).to eq 201
49
+ end
50
+ end
51
+ <%- end -%>
52
+
53
+ <%- if options["actions"].include? "update" -%>
54
+ put "/<%= plural_name -%>/:id" do
55
+ let(:id) { @<%= name.underscore -%>.id }
56
+
57
+ example "Updating a specific <%= name.underscore -%>" do
58
+ do_request(<%= name.underscore %>: @<%= name.underscore -%>.attributes.except("created_at").as_json)
59
+
60
+ expect(status).to eq 200
61
+ end
62
+ end
63
+ <%- end -%>
64
+
65
+ <%- if options["actions"].include? "destroy" -%>
66
+ delete "/<%= plural_name %>/:id" do
67
+ let(:id) { @<%= name.underscore %>.id }
68
+
69
+ example "Deleting a specific <%= name.underscore %>" do
70
+ do_request
71
+
72
+ expect(status).to eq 204
73
+ end
74
+ end
75
+ <%- end -%>
76
+ end
@@ -0,0 +1,12 @@
1
+ class <%= plural_name.camelize %>Controller < BaseApiController
2
+ <%= "actions :#{options['actions'].join(', :') }" if options['actions'].present? -%>
3
+
4
+ <% if options['permit_params'] -%>
5
+
6
+ private
7
+
8
+ def permitted_params
9
+ params.require(:<%= name.underscore -%>).permit(:<%= (class_name.constantize.new.attribute_names - ["created_at", "updated_at"]).join(', :') %>)
10
+ end
11
+ <% end -%>
12
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name -%>Serializer < ActiveModel::Serializer
2
+ attributes :<%= (class_name.constantize.new.attribute_names).join(', :') %>
3
+ end
@@ -0,0 +1,27 @@
1
+ module Harbourmaster
2
+ class InstallGenerator < Rails::Generators::Base
3
+ desc 'Creates a base api controller from which all other controllers will inherit. Also generates the serializer initializer.'
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_base_api_controller
8
+ copy_file 'base_api_controller.rb', 'app/controllers/base_api_controller.rb'
9
+ end
10
+
11
+ def initializer_responder
12
+ template 'json_responder.rb', 'lib/responders/json_responder.rb'
13
+ end
14
+
15
+ def initialize_active_model_serializers
16
+ copy_file 'active_model_serializer.rb', 'config/initializers/active_model_serializer.rb'
17
+ end
18
+
19
+ def initialize_api_docs
20
+ copy_file 'rspec_api_documentation.rb', 'config/initializers/rspec_api_documentation.rb'
21
+ end
22
+
23
+ def initialize_apitome
24
+ generate "apitome:install"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ ActiveModel::Serializer.setup do |config|
2
+ config.embed = :ids
3
+ config.embed_in_root = true
4
+ end
@@ -0,0 +1,28 @@
1
+ require 'json_responder'
2
+
3
+ class BaseApiController < InheritedResources::Base
4
+ respond_to :json
5
+ responders :json
6
+
7
+ def collection
8
+ limit_per_page = params[:per_page] || nil
9
+ @q = end_of_association_chain
10
+ @q = @q.search(params[:q])
11
+ @q = @q.result
12
+
13
+ @total_count = @q.length
14
+ limit_per_page ||= @total_count
15
+
16
+ # Pagination
17
+ if params[:from]
18
+ @q = @q.with_name_from(params[:from][:name], limit_per_page) if params[:from][:name]
19
+ @q = @q.with_field_from(params[:from][:field], params[:from][:value]) if params[:from][:field]
20
+ end
21
+
22
+ @q.limit(limit_per_page)
23
+ end
24
+
25
+ def default_serializer_options
26
+ { meta: { deleted_ids: end_of_association_chain.show_deleted_ids(params[:visible_ids]), pagination: { total_objects: @total_count } } }
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ <%- if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2 -%>
2
+ # Conform to http://jsonapi.org/format/ by returning the updated object from a PUT instead of HTTP spec's default of 204.
3
+ module Responders::JsonResponder
4
+ protected
5
+
6
+ # simply render the resource even on POST instead of redirecting for ajax
7
+ def api_behavior
8
+ if post?
9
+ display resource, status: :created
10
+ # render resource instead of 204 no content
11
+ elsif put?
12
+ display resource, status: :ok
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ <%- else -%>
19
+ # Conform to http://jsonapi.org/format/ by returning the updated object from a PUT instead of HTTP spec's default of 204.
20
+ module Responders::JsonResponder
21
+ protected
22
+
23
+ # simply render the resource even on POST instead of redirecting for ajax
24
+ def api_behavior(error)
25
+ if post?
26
+ display resource, status: :created
27
+ # render resource instead of 204 no content
28
+ elsif put?
29
+ display resource, status: :ok
30
+ else
31
+ super
32
+ end
33
+ end
34
+ end
35
+ <%- end -%>
@@ -0,0 +1,69 @@
1
+ # Values listed are the default values
2
+ RspecApiDocumentation.configure do |config|
3
+ # Set the application that Rack::Test uses
4
+ config.app = Rails.application
5
+
6
+ # Output folder
7
+ config.docs_dir = Rails.root.join("doc", "api")
8
+
9
+ # An array of output format(s).
10
+ # Possible values are :json, :html, :combined_text, :combined_json,
11
+ # :json_iodocs, :textile, :markdown, :append_json
12
+ config.format = [:json]
13
+
14
+ # Location of templates
15
+ config.template_path = "inside of the gem"
16
+
17
+ # Filter by example document type
18
+ config.filter = :all
19
+
20
+ # Filter by example document type
21
+ config.exclusion_filter = nil
22
+
23
+ # Used when adding a cURL output to the docs
24
+ config.curl_host = nil
25
+
26
+ # Used when adding a cURL output to the docs
27
+ # Allows you to filter out headers that are not needed in the cURL request,
28
+ # such as "Host" and "Cookie". Set as an array.
29
+ config.curl_headers_to_filter = nil
30
+
31
+ # By default, when these settings are nil, all headers are shown,
32
+ # which is sometimes too chatty. Setting the parameters to an
33
+ # array of headers will render *only* those headers.
34
+ config.request_headers_to_include = nil
35
+ config.response_headers_to_include = nil
36
+
37
+ # By default examples and resources are ordered by description. Set to true keep
38
+ # the source order.
39
+ config.keep_source_order = false
40
+
41
+ # Change the name of the API on index pages
42
+ config.api_name = "API Documentation"
43
+
44
+ # Redefine what method the DSL thinks is the client
45
+ # This is useful if you need to `let` your own client, most likely a model.
46
+ config.client_method = :client
47
+
48
+ # Change the IODocs writer protocol
49
+ config.io_docs_protocol = "http"
50
+
51
+ # You can define documentation groups as well. A group allows you generate multiple
52
+ # sets of documentation.
53
+ config.define_group :public do |config|
54
+ # By default the group's doc_dir is a subfolder under the parent group, based
55
+ # on the group's name.
56
+ config.docs_dir = Rails.root.join("doc", "api", "public")
57
+
58
+ # Change the filter to only include :public examples
59
+ config.filter = :public
60
+ end
61
+
62
+ # Change how the post body is formatted by default, you can still override by `raw_post`
63
+ # Can be :json, :xml, or a proc that will be passed the params
64
+ config.post_body_formatter = Proc.new { |params| params }
65
+
66
+ # Change the embedded style for HTML output. This file will not be processed by
67
+ # RspecApiDocumentation and should be plain CSS.
68
+ config.html_embedded_css_file = nil
69
+ end
@@ -0,0 +1,3 @@
1
+ module Harbourmaster
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "rspec"
2
+ require "rspec_api_documentation"
3
+ require "active_model_serializers"
4
+ require "inherited_resources"
5
+ require "apitome"
6
+ require "responders"
7
+ require "ransack"
8
+
9
+ module Harbourmaster
10
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :harbourmaster do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harbourmaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Isaac Norman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 3.2.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 3.2.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: active_model_serializers
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.9.3
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec_api_documentation
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '='
66
+ - !ruby/object:Gem::Version
67
+ version: 4.3.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '='
73
+ - !ruby/object:Gem::Version
74
+ version: 4.3.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: inherited_resources
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 1.6.0
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 1.6.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: responders
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 2.1.0
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 2.1.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: ragamuffins
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.5
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 1.0.5
117
+ - !ruby/object:Gem::Dependency
118
+ name: paginative
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.0.18
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.0.18
131
+ - !ruby/object:Gem::Dependency
132
+ name: ransack
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 1.6.4
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 1.6.4
145
+ - !ruby/object:Gem::Dependency
146
+ name: apitome
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 0.0.8
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: 0.0.8
159
+ - !ruby/object:Gem::Dependency
160
+ name: factory_girl_rails
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: sqlite3
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description: Rails generator for making documented API controllers
188
+ email:
189
+ - idn@papercloud.com.au
190
+ executables: []
191
+ extensions: []
192
+ extra_rdoc_files: []
193
+ files:
194
+ - MIT-LICENSE
195
+ - README.rdoc
196
+ - Rakefile
197
+ - lib/generators/harbourmaster/controller/controller_generator.rb
198
+ - lib/generators/harbourmaster/controller/templates/acceptance_tests.rb
199
+ - lib/generators/harbourmaster/controller/templates/controller.rb
200
+ - lib/generators/harbourmaster/controller/templates/serializer.rb
201
+ - lib/generators/harbourmaster/install/install_generator.rb
202
+ - lib/generators/harbourmaster/install/templates/active_model_serializer.rb
203
+ - lib/generators/harbourmaster/install/templates/base_api_controller.rb
204
+ - lib/generators/harbourmaster/install/templates/json_responder.rb
205
+ - lib/generators/harbourmaster/install/templates/rspec_api_documentation.rb
206
+ - lib/harbourmaster.rb
207
+ - lib/harbourmaster/version.rb
208
+ - lib/tasks/harbourmaster_tasks.rake
209
+ homepage: https://github.com/Papercloud/Harbourmaster
210
+ licenses:
211
+ - MIT
212
+ metadata: {}
213
+ post_install_message:
214
+ rdoc_options: []
215
+ require_paths:
216
+ - lib
217
+ required_ruby_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubyforge_project:
229
+ rubygems_version: 2.4.3
230
+ signing_key:
231
+ specification_version: 4
232
+ summary: Take control of your doc(k)s
233
+ test_files: []