apiblueprint-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d759b00f7d866a0a4c9ce7b7e3a8dbd1dff31689
4
+ data.tar.gz: ac8ba99cd91677e1abfc3c8df346ed88e0f19f6b
5
+ SHA512:
6
+ metadata.gz: dbffc1b4e3ed117140257ee2fb2747ecde33a364d14e91858769b7885e4ab2b517be4be09aa40efabb1da1c6817339ceefb4a30f91b1ebaa15ecc89495c9f034
7
+ data.tar.gz: 91ca08cff849f7748d617fccd8072a70b037dcd787b223d72940553401496ef8c46dea2fce82b6f2d5af6ee82da14d0a7cab3193da3f890b6f0e59c8ea657a09
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apiblueprint-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Naoyoshi Aikawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # apiblueprint-rails
2
+
3
+ apiblueprint-rails creates [API Blueprint](https://apiblueprint.org/) boilerplate when calling `rails g apiblueprint`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your rails application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiblueprint-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ After installing apiblueprint-rails to your rails application, use apiblueprint keyword to generate scaffold.
22
+ For example,
23
+
24
+ ```bash
25
+ $ rails g apiblueprint User name age:integer admin:boolean
26
+ ```
27
+
28
+ creates `doc/users.apib` file.
29
+
30
+ You can change `doc` directory by passing `--apidoc-dir=<directory>` flag to the option.
31
+
32
+
33
+ If you want to generate apiblueprint only, you can use `rails generate apiblueprint --generate=none` command.
34
+
35
+ ```bash
36
+ $ rails g apiblueprint --generate=none User name age:integer admin:boolean
37
+ ```
38
+
39
+ generates just the same apib output above.
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apiblueprint-rails.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apiblueprint/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apiblueprint-rails"
8
+ spec.version = Apiblueprint::Rails::VERSION
9
+ spec.authors = ["Naoyoshi Aikawa"]
10
+ spec.email = ["nao@wantedly.com", "dev@wantedly.com"]
11
+
12
+ spec.summary = "API Blueprint generator for Rails"
13
+ spec.description = "apiblueprint-rails creates API Blueprint boilerplate when generating scaffold by rails"
14
+ spec.homepage = "https://github.com/wantedly/apiblueprint-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "railties", "~> 3.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apiblueprint/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ module Apiblueprint
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "apiblueprint/rails/version"
2
+
3
+ module Apiblueprint
4
+ module Rails
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate apiblueprint Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,45 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ class Rails::ApiblueprintGenerator < Rails::Generators::NamedBase
4
+ desc "create apiblueprint file"
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ argument(
8
+ :attributes,
9
+ type: :array,
10
+ default: [],
11
+ banner: "field:type field:type"
12
+ )
13
+
14
+ class_option "apidoc-dir", type: :string, default: "doc", desc: "Change doc directory by passing"
15
+ class_option "generate", type: :string, default: "scaffold", desc: "Change generate type (Default:scaffold, Other: none, controller, model...)"
16
+
17
+ def set_attribute
18
+ @attrs = Array.new()
19
+ @args = Array.new()
20
+ attributes.map do |val|
21
+ @attrs.push( { name: val.name, type: val.type, init: val.default } )
22
+ end
23
+ @attrs.map do |attr|
24
+ @args.push(attr[:name].to_s + ":" + attr[:type].to_s)
25
+ case attr[:type].to_s
26
+ when "integer", "primary_key", "decimal", "float" then
27
+ attr[:type] = "number"
28
+ when "boolean" then
29
+ attr[:type] = "boolean"
30
+ when "references" then
31
+ attr[:name] = attr[:name] + "_id"
32
+ attr[:type] = "number, required"
33
+ else
34
+ attr[:type] = "string"
35
+ end
36
+ end
37
+ end
38
+
39
+ def create_apib_file
40
+ template "apiblueprint.erb", "#{options["apidoc-dir"]}/#{file_name}.apib"
41
+ if options["generate"] != "none" then
42
+ invoke(options["generate"], [file_name, @args])
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,74 @@
1
+
2
+ FORMAT: 1A
3
+
4
+ # <%= file_name %> API
5
+
6
+ Write an overall API discription.
7
+
8
+ # <%= plural_table_name %> action [<%= route_url %>]
9
+
10
+ Write a discription.
11
+
12
+ ## Create <%= singular_table_name %> [POST]
13
+
14
+ Write a [POST] discription.
15
+
16
+ + Request <%= table_name %> (application/json; charset=utf-8)
17
+ + Attributes
18
+ <% @attrs.map do |attr| %>+ <%= attr[:name] %>: <%= attr[:init] %> (<%= attr[:type] %>)
19
+ <% end %>
20
+ + Response 201 (application/json; charset=utf-8)
21
+ + Attributes (<%= table_name %>)
22
+
23
+ ## Get <%= plural_table_name %> [GET]
24
+
25
+ Write a [GET] discription.
26
+
27
+ + Response 200 (application/json; charset=utf-8)
28
+ + Attributes (array)
29
+ + (<%= table_name %>)
30
+ + (<%= table_name %>)
31
+
32
+ # <%= singular_table_name %> action [<%= route_url %>/{id}]
33
+
34
+ Write a discription.
35
+
36
+ + Parameters
37
+ + id: `1` (enum[string]) - The ID of the desired <%= singular_table_name %>.
38
+ + Members
39
+ + `1`
40
+ + `2`
41
+ + `3`
42
+
43
+ ## Get <%= singular_table_name %> [GET]
44
+
45
+ Write a [GET] discription.
46
+
47
+ + Response 200 (application/json; charset=utf-8)
48
+ + Attributes (<%= table_name %>)
49
+
50
+ ## Update <%= singular_table_name %> [PUT]
51
+
52
+ Write a [PUT] discription.
53
+
54
+ + Request <%= table_name %> (application/json; charset=utf-8)
55
+ + Attributes
56
+ <% @attrs.map do |attr| %>+ <%= attr[:name] %>: <%= attr[:init] %> (<%= attr[:type] %>)
57
+ <% end %>
58
+ + Response 200 (application/json; charset=utf-8)
59
+ + Attributes (<%= table_name %>)
60
+
61
+ ## Delete <%= singular_table_name %> [DELETE]
62
+
63
+ Write a [DELETE] discription.
64
+
65
+ + Response 204
66
+
67
+ # Data Structures
68
+
69
+ ## <%= table_name %> (object)
70
+
71
+ + id: 1 (number) - Id<% @attrs.map do |attr| %>
72
+ + <%= attr[:name] %>: <%= attr[:init] %> (<%= attr[:type] %>)<% end %>
73
+ + created_at: `2000-01-01 00:00:00` (string) - CreatedTime
74
+ + updated_at: `2000-01-01 00:00:00` (string) - UpdatedTime
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiblueprint-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naoyoshi Aikawa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: apiblueprint-rails creates API Blueprint boilerplate when generating
70
+ scaffold by rails
71
+ email:
72
+ - nao@wantedly.com
73
+ - dev@wantedly.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - apiblueprint-rails.gemspec
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/apiblueprint/rails.rb
89
+ - lib/apiblueprint/rails/version.rb
90
+ - lib/generators/rails/apiblueprint/USAGE
91
+ - lib/generators/rails/apiblueprint/apiblueprint_generator.rb
92
+ - lib/generators/rails/apiblueprint/templates/apiblueprint.erb
93
+ homepage: https://github.com/wantedly/apiblueprint-rails
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: API Blueprint generator for Rails
117
+ test_files: []
118
+ has_rdoc: