nucleus 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +18 -4
- data/README.md +28 -40
- data/Rakefile +137 -137
- data/config/nucleus_config.rb +0 -4
- data/lib/nucleus/adapter_resolver.rb +115 -115
- data/lib/nucleus/adapters/buildpack_translator.rb +79 -79
- data/lib/nucleus/adapters/v1/cloud_control/application.rb +108 -108
- data/lib/nucleus/adapters/v1/cloud_control/authentication.rb +27 -27
- data/lib/nucleus/adapters/v1/cloud_control/cloud_control.rb +153 -153
- data/lib/nucleus/adapters/v1/cloud_control/domains.rb +68 -68
- data/lib/nucleus/adapters/v1/cloud_control/logs.rb +103 -103
- data/lib/nucleus/adapters/v1/cloud_control/vars.rb +88 -88
- data/lib/nucleus/adapters/v1/cloud_foundry_v2/domains.rb +149 -149
- data/lib/nucleus/adapters/v1/cloud_foundry_v2/logs.rb +303 -303
- data/lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb +286 -286
- data/lib/nucleus/adapters/v1/heroku/heroku.rb +2 -2
- data/lib/nucleus/adapters/v1/heroku/logs.rb +108 -108
- data/lib/nucleus/core/adapter_authentication_inductor.rb +0 -2
- data/lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb +37 -37
- data/lib/nucleus/core/adapter_extensions/http_client.rb +177 -177
- data/lib/nucleus/core/common/files/archive_extractor.rb +112 -112
- data/lib/nucleus/core/common/files/archiver.rb +91 -91
- data/lib/nucleus/core/common/logging/request_log_formatter.rb +48 -48
- data/lib/nucleus/core/error_messages.rb +127 -127
- data/lib/nucleus/core/models/abstract_model.rb +29 -29
- data/lib/nucleus/scripts/load_dependencies.rb +0 -1
- data/lib/nucleus/scripts/setup_config.rb +28 -28
- data/lib/nucleus/version.rb +3 -3
- data/nucleus.gemspec +10 -12
- data/spec/factories/models.rb +63 -61
- data/spec/integration/api/auth_spec.rb +58 -58
- data/spec/test_suites.rake +31 -31
- data/spec/unit/common/helpers/auth_helper_spec.rb +73 -73
- data/spec/unit/common/oauth2_auth_client_spec.rb +1 -1
- data/tasks/compatibility.rake +113 -113
- data/tasks/evaluation.rake +162 -162
- metadata +16 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a510c433f1548f80c42ce3d32804e73b7c71640
|
4
|
+
data.tar.gz: 46ff6af1d76e37cc945ea45a455968dded34533e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ffe6b03100aebabed7d6dbbc25cf714252b5985bbbc8708620688b84367082bdd2b39af34aa0c32094f0b155cf687a5e182385686dc505fbc6c1ab0f9a4bb4
|
7
|
+
data.tar.gz: 5668c6da41e685a1e6b65e0d7d6c0f84a93ac70d1f936e89227aa93558c76d949ffa2a8d7164ba18bb4ec68a7ce7692874279201dae9476ec7613f94e6ddb239
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,15 +4,29 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
## Unreleased - Next
|
6
6
|
|
7
|
-
### Added
|
7
|
+
### Added
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
|
12
|
+
### Removed
|
13
|
+
|
14
|
+
|
15
|
+
## [0.2.0] - 2016-01-22
|
16
|
+
|
17
|
+
### Added
|
8
18
|
* Add basic logging functionality for OpenShift v2
|
19
|
+
* Add more providers and endpoints to the default configuration
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
* Correctly URL-encode credentials for Heroku authentication
|
9
23
|
|
10
|
-
###
|
11
|
-
*
|
24
|
+
### Removed
|
25
|
+
* LMDB is the only packaged data store from now on
|
12
26
|
|
13
27
|
## [0.1.0] - 2015-08-04
|
14
28
|
|
15
|
-
### Added
|
29
|
+
### Added
|
16
30
|
* Initial development release of the Platform as a Service abstraction layer - [@croeck](https://github.com/croeck)
|
17
31
|
|
18
32
|
|
data/README.md
CHANGED
@@ -4,15 +4,13 @@
|
|
4
4
|
[![Dependency Status](https://gemnasium.com/stefan-kolb/nucleus.svg)](https://gemnasium.com/stefan-kolb/nucleus)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/stefan-kolb/nucleus/badges/gpa.svg)](https://codeclimate.com/github/stefan-kolb/nucleus)
|
6
6
|
[![Test Coverage](https://codeclimate.com/github/stefan-kolb/nucleus/badges/coverage.svg)](https://codeclimate.com/github/stefan-kolb/nucleus/coverage)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/nucleus.svg)](https://badge.fury.io/rb/nucleus)
|
8
|
+
|
9
|
+
_Nucleus_ is a RESTful abstraction layer and Ruby gem to unify core management functions of Platform as a Service (PaaS) systems.
|
7
10
|
|
8
|
-
_Nucleus_ is a RESTful abstraction layer to unify core management functions of Platform-as-a-Service (PaaS) systems.
|
9
11
|
The API is build using [Ruby](https://www.ruby-lang.org) and the [grape framework](https://github.com/intridea/grape).
|
10
12
|
It provides fully compliant [swagger](http://swagger.io/) schemas that serve for documentation and client generation.
|
11
13
|
|
12
|
-
Nucleus differentiates between Vendors, Providers and Endpoints.
|
13
|
-
A *Vendor* is the organization that developed the platform software.
|
14
|
-
A *Provider* runs the platform, which always has at least one *Endpoint*, but can also have multiple endpoints for different regions.
|
15
|
-
|
16
14
|
## Table of Contents
|
17
15
|
|
18
16
|
* [Supported Vendors](#supported-vendors)
|
@@ -90,14 +88,13 @@ Please make sure to obey the following installation instructions before starting
|
|
90
88
|
### Ruby Interpreter Compatibility
|
91
89
|
|
92
90
|
Nucleus is supposed to run on Ruby >= 2.0.
|
93
|
-
|
91
|
+
Due to native gem dependencies, it currently won't work on JRuby.
|
94
92
|
|
95
93
|
### Installation instructions
|
96
94
|
|
97
|
-
1) The following
|
95
|
+
1) The following executables must be available on the system's *PATH*:
|
98
96
|
|
99
|
-
|
100
|
-
- ssh
|
97
|
+
git, ssh
|
101
98
|
|
102
99
|
#### Platform-specific notes
|
103
100
|
|
@@ -105,10 +102,10 @@ Unix systems should run fine out of the box, whereas Windows systems might need
|
|
105
102
|
|
106
103
|
##### Windows
|
107
104
|
|
108
|
-
Both
|
105
|
+
Both required executables should be located in the `Git/bin` installation directory of [msysGit](https://msysgit.github.io/).
|
109
106
|
Nucleus is verified to work with [msysGit](https://msysgit.github.io/) and the included version of `OpenSSH`.
|
110
107
|
We did not verify other alternatives, e.g. PuTTY's `plink.exe`.
|
111
|
-
PuTTY is supposed to
|
108
|
+
PuTTY is supposed to not work due to the lack of the `-o UserKnownHostsFile=NUL -o StrictHostKeyChecking=no` options that allow to connect any git repository without confirmation of the host's identity.
|
112
109
|
|
113
110
|
###### Troubleshooting
|
114
111
|
|
@@ -149,13 +146,13 @@ upon which you would update your bundle.
|
|
149
146
|
$ bundle install
|
150
147
|
```
|
151
148
|
|
152
|
-
|
149
|
+
Or install the gem by yourself:
|
153
150
|
|
154
151
|
```shell
|
155
152
|
$ gem install nucleus
|
156
153
|
```
|
157
154
|
|
158
|
-
Finally require the gem
|
155
|
+
Finally, require the gem inside your application
|
159
156
|
|
160
157
|
```ruby
|
161
158
|
require 'nucleus'
|
@@ -165,7 +162,7 @@ require 'nucleus'
|
|
165
162
|
|
166
163
|
1) Configuration [optional]
|
167
164
|
|
168
|
-
Adapt the configuration to your needs and adjust the values via `nucleus_config
|
165
|
+
Adapt the configuration to your needs and adjust the values via the global `nucleus_config` variable.
|
169
166
|
The configuration *must* be changed before initializing the `AdapterResolver`, otherwise the configuration is locked and can't be changed anymore.
|
170
167
|
|
171
168
|
For more information have a look at the [configuration](#configuration) section.
|
@@ -176,7 +173,7 @@ For more information have a look at the [configuration](#configuration) section.
|
|
176
173
|
Nucleus::VersionDetector.api_versions
|
177
174
|
```
|
178
175
|
|
179
|
-
3) Instantiate
|
176
|
+
3) Instantiate an `AdapterResolver` for the desired API version:
|
180
177
|
|
181
178
|
```ruby
|
182
179
|
resolver = Nucleus::AdapterResolver.new('v1')
|
@@ -189,7 +186,7 @@ resolver.adapters
|
|
189
186
|
```
|
190
187
|
|
191
188
|
```ruby
|
192
|
-
{"cloudcontrol"=>Nucleus::Adapters::V1::CloudControl, "cloud_foundry_v2"=>Nucleus::Adapters::V1::CloudFoundryV2, "heroku"=>Nucleus::Adapters::V1::Heroku, "openshift_v2"=>Nucleus::Adapters::V1::OpenshiftV2}
|
189
|
+
{ "cloudcontrol"=>Nucleus::Adapters::V1::CloudControl, "cloud_foundry_v2"=>Nucleus::Adapters::V1::CloudFoundryV2, "heroku"=>Nucleus::Adapters::V1::Heroku, "openshift_v2"=>Nucleus::Adapters::V1::OpenshiftV2 }
|
193
190
|
```
|
194
191
|
|
195
192
|
5) Load your desired adapter implementation:
|
@@ -199,10 +196,11 @@ adapter = resolver.load('cloudcontrol', 'api.cloudcontrol.com', 'your_username',
|
|
199
196
|
```
|
200
197
|
|
201
198
|
By default, the adapter will be populated with the default configuration options that are defined in the vendor's configuration for the selected endpoint_url.
|
202
|
-
If you are using a custom installation, e.g. of *
|
199
|
+
If you are using a custom installation, e.g. of *OpenShift* or *Cloud Foundry*, make sure to pass the option that describes the `app_domain` for deployed applications.
|
203
200
|
Otherwise, the `web_url` links created by Nucleus will be malformed.
|
204
201
|
|
205
202
|
```ruby
|
203
|
+
minimal = resolver.load('heroku', 'your_username', 'your_password')
|
206
204
|
adapter = resolver.load('cloud_foundry_v2', 'api.example.org', 'your_username', 'your_password', app_domain: 'apps.example.org', check_ssl: false)
|
207
205
|
```
|
208
206
|
|
@@ -217,7 +215,7 @@ app = adapter.create_application(region: 'default', name: 'myusersfirstapplicati
|
|
217
215
|
adapter.delete_application(app[:id])
|
218
216
|
```
|
219
217
|
|
220
|
-
Check the **documentation** of the `Nucleus::Adapters::V1::Stub` adapter (or any other API version) for a complete list of
|
218
|
+
Check the **documentation** of the `Nucleus::Adapters::V1::Stub` adapter (or any other API version) for a complete list of supported actions.
|
221
219
|
You can also refer to the documentation of the REST interface to get detailed information about the parameter options of `post` and `put` commands,
|
222
220
|
including which fields are required and those that are only optional.
|
223
221
|
|
@@ -259,7 +257,7 @@ After you started a server instance, you can access an interactive [swagger-ui](
|
|
259
257
|
## Functionality
|
260
258
|
|
261
259
|
The following list shows the degree to which the adapters implement the offered methods.
|
262
|
-
This list
|
260
|
+
This list can be auto-generated via:
|
263
261
|
|
264
262
|
```
|
265
263
|
$ bundle exec rake evaluation:compatibility:markdown
|
@@ -310,32 +308,30 @@ remove_service|✓|✓|✓|✓
|
|
310
308
|
### Core constructs
|
311
309
|
|
312
310
|
Nucleus could support any constellation of PaaS offers that are currently available.
|
313
|
-
In order to do so, we differentiate between
|
311
|
+
In order to do so, we differentiate between between vendors, providers, and endpoints:
|
314
312
|
|
315
|
-
|
316
|
-
|
317
|
-
the **endpoint** of the provider's offer.
|
313
|
+
A *vendor* is the organization that developed the platform software, which also determines the offered functionalities.
|
314
|
+
A *provider* runs the platform, which always has at least one *endpoint*.
|
318
315
|
|
319
316
|
For most scenarios the *endpoint* is identical to the *provider*, but in some cases,
|
320
317
|
for instance on [IBM Bluemix][bluemix], *endpoints* distinguish different deployment regions.
|
321
318
|
|
322
|
-
If running Nucleus as web service, all changes made to these entities at runtime will be discarded,
|
323
|
-
unless you enable the functionality in the configuration and specify a location where to persist the data to.
|
319
|
+
If running Nucleus as web service, all changes made to these entities at runtime will be discarded, unless you enable persistence functionality in the configuration and specify a location where to persist the data to.
|
324
320
|
|
325
321
|
#### Vendors
|
326
322
|
|
327
323
|
You can use the API of Nucleus to show a list of all supported vendors.
|
328
324
|
This request is publicly available and does not require any authentication.
|
329
325
|
|
330
|
-
However, you
|
331
|
-
All developers that want to have more information on how to add a new vendor
|
326
|
+
However, you cannot create, delete or update a vendor at runtime because it represents the logic to communicate with the associated platform.
|
327
|
+
All developers that want to have more information on how to add a new vendor, please see the instructions: [Add a vendor (or implement a new adapter)](wiki/implement_new_adapter.md)
|
332
328
|
|
333
329
|
#### Providers and Endpoints
|
334
330
|
|
335
331
|
Providers and Endpoints can be managed *without authentication* and support `GET`, `POST`, `PATCH`, `DELETE` requests.
|
336
332
|
|
337
333
|
A new entity can be registered at runtime by sending a `POST` request.
|
338
|
-
Whereas a provider only requires a `name`, an endpoint also needs
|
334
|
+
Whereas a provider only requires a `name`, an endpoint also needs the `url` as further attribute.
|
339
335
|
Please refer to the swagger-ui documentation for additional information about the requests.
|
340
336
|
|
341
337
|
### Authentication
|
@@ -345,13 +341,12 @@ The credentials must be provided as [Basic authentication](https://en.wikipedia.
|
|
345
341
|
|
346
342
|
Authorization: Basic thebase64encodedcredentialsstring
|
347
343
|
|
348
|
-
#### Special characters
|
344
|
+
#### Special characters
|
349
345
|
|
350
|
-
The usage of special characters, for instance german umlauts
|
351
|
-
Please make sure to select the correct encoding for your credentials before encoding them with
|
346
|
+
The usage of special characters, for instance german umlauts may cause issues with some platforms.
|
347
|
+
Please make sure to select the correct encoding for your credentials before encoding them with Base64:
|
352
348
|
|
353
|
-
* Stackato 3.4.2
|
354
|
-
* Different encodings cause the requests to crash and return status 500
|
349
|
+
* Stackato 3.4.2: Different encodings cause the requests to crash and return status 500
|
355
350
|
|
356
351
|
### Application logs
|
357
352
|
|
@@ -512,13 +507,6 @@ They are described with increasing importance, meaning that the last option over
|
|
512
507
|
1. A file in user account's home directory. On UNIX systems this file must be placed at `~/.nucleus/nucleus_config.rb`, whereas it is expected at `~/nucleus/nucleus_config.rb` if running Windows.
|
513
508
|
2. The `config/nucleus_config.rb` file in the project's directory
|
514
509
|
|
515
|
-
#### Database backend
|
516
|
-
|
517
|
-
The database backend can be specified in the `config/nucleus_config.rb` configuration file.
|
518
|
-
It defaults to [Daybreak](https://github.com/propublica/daybreak) on Unix systems and [LMDB](https://github.com/minad/lmdb) on Windows.
|
519
|
-
|
520
|
-
Note: *[Daybreak](https://github.com/propublica/daybreak) does not run on Windows*
|
521
|
-
|
522
510
|
### Vendors, Providers, and Endpoints
|
523
511
|
|
524
512
|
A vendor is reflected by an adapter implementation, but the providers and their endpoints can either be changed at runtime or via `.yaml` configuration files.
|
data/Rakefile
CHANGED
@@ -1,137 +1,137 @@
|
|
1
|
-
import 'tasks/compatibility.rake'
|
2
|
-
import 'tasks/evaluation.rake'
|
3
|
-
import 'spec/test_suites.rake'
|
4
|
-
|
5
|
-
require 'rake'
|
6
|
-
require 'rubygems'
|
7
|
-
require 'bundler'
|
8
|
-
require 'bundler/gem_tasks'
|
9
|
-
require 'rspec/core/rake_task'
|
10
|
-
require 'rainbow/ext/string' unless String.respond_to?(:color)
|
11
|
-
require 'rubocop/rake_task'
|
12
|
-
|
13
|
-
RuboCop::RakeTask.new
|
14
|
-
|
15
|
-
# first check code style, then execute the tests
|
16
|
-
task default: [:rubocop, :spec]
|
17
|
-
|
18
|
-
# map spec task to all test suites
|
19
|
-
task :spec do
|
20
|
-
# first, run all tests
|
21
|
-
Rake::Task['spec:suite:all'].invoke
|
22
|
-
# if on the CI system, push coverage report to codeclimate
|
23
|
-
if ENV['CODECLIMATE_REPO_TOKEN']
|
24
|
-
require 'simplecov'
|
25
|
-
require 'codeclimate-test-reporter'
|
26
|
-
CodeClimate::TestReporter::Formatter.new.format(SimpleCov.result)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
task :doc_toc do
|
31
|
-
File.open('README.md', 'r') do |f|
|
32
|
-
f.each_line do |line|
|
33
|
-
forbidden_words = ['Table of contents', 'define', 'pragma']
|
34
|
-
next if !line.start_with?('#') || forbidden_words.any? { |w| line =~ /#{w}/ }
|
35
|
-
|
36
|
-
title = line.delete('#').strip
|
37
|
-
href = title.tr(' ', '-').downcase
|
38
|
-
puts ' ' * (line.count('#') - 1) + "* [#{title}](\##{href})"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
desc 'Record all adapter tests'
|
44
|
-
task :record do
|
45
|
-
# http://www.relishapp.com/vcr/vcr/v/2-9-3/docs/record-modes
|
46
|
-
ENV['VCR_RECORD_MODE'] = 'once'
|
47
|
-
# recording only valid for adapter tests
|
48
|
-
Rake::Task['spec:suite:adapters'].invoke
|
49
|
-
end
|
50
|
-
|
51
|
-
namespace :record do
|
52
|
-
FileList['spec/adapter/v1/**'].each do |file|
|
53
|
-
next unless File.directory?(file)
|
54
|
-
adapter = File.basename(file)
|
55
|
-
|
56
|
-
desc "Record #{adapter} adapter tests"
|
57
|
-
RSpec::Core::RakeTask.new(adapter) do |t|
|
58
|
-
# new_episodes
|
59
|
-
ENV['VCR_RECORD_MODE'] = 'once'
|
60
|
-
t.pattern = "spec/adapter/v1/#{adapter}/*_spec.rb"
|
61
|
-
t.verbose = true
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
task :environment do
|
67
|
-
ENV['RACK_ENV'] ||= 'development'
|
68
|
-
require 'configatron'
|
69
|
-
require 'nucleus/scripts/setup_config'
|
70
|
-
nucleus_config.logging.level = Logger::Severity::ERROR
|
71
|
-
require 'nucleus_api/scripts/load_api'
|
72
|
-
require 'nucleus_api/scripts/initialize_api'
|
73
|
-
end
|
74
|
-
|
75
|
-
task routes: :environment do
|
76
|
-
Nucleus::API::RootAPI.routes.each do |route|
|
77
|
-
next if route.nil? || route.route_method.nil?
|
78
|
-
method = route.route_method.ljust(10)
|
79
|
-
path = route.route_path
|
80
|
-
version = route.instance_variable_get(:@options)[:version]
|
81
|
-
path = path.gsub(/:version/, version) unless version.nil?
|
82
|
-
puts " #{method} #{path} - [#{version}]"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
task schema_v1: :environment do
|
87
|
-
require 'json'
|
88
|
-
response = Nucleus::API::RootAPI.call(
|
89
|
-
'REQUEST_METHOD' => 'GET',
|
90
|
-
'PATH_INFO' => '/schema',
|
91
|
-
'rack.input' => StringIO.new)[2].body[0]
|
92
|
-
json = JSON.parse(response)
|
93
|
-
puts JSON.pretty_generate(json)
|
94
|
-
end
|
95
|
-
|
96
|
-
begin
|
97
|
-
require 'yard'
|
98
|
-
DOC_FILES = %w(lib/**/*.rb)
|
99
|
-
|
100
|
-
YARD::Rake::YardocTask.new(:doc) do |t|
|
101
|
-
t.files = DOC_FILES
|
102
|
-
end
|
103
|
-
|
104
|
-
namespace :doc do
|
105
|
-
YARD::Rake::YardocTask.new(:pages) do |t|
|
106
|
-
t.files = DOC_FILES
|
107
|
-
t.options = ['-o', '../nucleus.doc/docs', '--title', "Nucleus #{Nucleus::VERSION} Documentation"]
|
108
|
-
end
|
109
|
-
|
110
|
-
desc 'Check out gh-pages.'
|
111
|
-
task :checkout do
|
112
|
-
dir = File.join(__dir__, '..', 'nucleus.doc')
|
113
|
-
unless Dir.exist?(dir)
|
114
|
-
Dir.mkdir(dir)
|
115
|
-
Dir.chdir(dir) do
|
116
|
-
system('git init')
|
117
|
-
system('git remote add origin git@github.com:stefan-kolb/nucleus.git')
|
118
|
-
system('git pull')
|
119
|
-
system('git checkout gh-pages')
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
desc 'Generate and publish YARD docs to GitHub pages.'
|
125
|
-
task publish: %w(doc:pages:checkout doc:pages) do
|
126
|
-
Dir.chdir(File.join(__dir__, '..', 'nucleus.doc')) do
|
127
|
-
system('git checkout gh-pages')
|
128
|
-
system('git add .')
|
129
|
-
system('git add -u')
|
130
|
-
system("git commit -m 'Generating docs for version #{Nucleus::VERSION}.'")
|
131
|
-
system('git push origin gh-pages')
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
rescue LoadError
|
136
|
-
puts 'You need to install YARD.'
|
137
|
-
end
|
1
|
+
import 'tasks/compatibility.rake'
|
2
|
+
import 'tasks/evaluation.rake'
|
3
|
+
import 'spec/test_suites.rake'
|
4
|
+
|
5
|
+
require 'rake'
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler'
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
require 'rainbow/ext/string' unless String.respond_to?(:color)
|
11
|
+
require 'rubocop/rake_task'
|
12
|
+
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
# first check code style, then execute the tests
|
16
|
+
task default: [:rubocop, :spec]
|
17
|
+
|
18
|
+
# map spec task to all test suites
|
19
|
+
task :spec do
|
20
|
+
# first, run all tests
|
21
|
+
Rake::Task['spec:suite:all'].invoke
|
22
|
+
# if on the CI system, push coverage report to codeclimate
|
23
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
24
|
+
require 'simplecov'
|
25
|
+
require 'codeclimate-test-reporter'
|
26
|
+
CodeClimate::TestReporter::Formatter.new.format(SimpleCov.result)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
task :doc_toc do
|
31
|
+
File.open('README.md', 'r') do |f|
|
32
|
+
f.each_line do |line|
|
33
|
+
forbidden_words = ['Table of contents', 'define', 'pragma']
|
34
|
+
next if !line.start_with?('#') || forbidden_words.any? { |w| line =~ /#{w}/ }
|
35
|
+
|
36
|
+
title = line.delete('#').strip
|
37
|
+
href = title.tr(' ', '-').downcase
|
38
|
+
puts ' ' * (line.count('#') - 1) + "* [#{title}](\##{href})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Record all adapter tests'
|
44
|
+
task :record do
|
45
|
+
# http://www.relishapp.com/vcr/vcr/v/2-9-3/docs/record-modes
|
46
|
+
ENV['VCR_RECORD_MODE'] = 'once'
|
47
|
+
# recording only valid for adapter tests
|
48
|
+
Rake::Task['spec:suite:adapters'].invoke
|
49
|
+
end
|
50
|
+
|
51
|
+
namespace :record do
|
52
|
+
FileList['spec/adapter/v1/**'].each do |file|
|
53
|
+
next unless File.directory?(file)
|
54
|
+
adapter = File.basename(file)
|
55
|
+
|
56
|
+
desc "Record #{adapter} adapter tests"
|
57
|
+
RSpec::Core::RakeTask.new(adapter) do |t|
|
58
|
+
# new_episodes
|
59
|
+
ENV['VCR_RECORD_MODE'] = 'once'
|
60
|
+
t.pattern = "spec/adapter/v1/#{adapter}/*_spec.rb"
|
61
|
+
t.verbose = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
task :environment do
|
67
|
+
ENV['RACK_ENV'] ||= 'development'
|
68
|
+
require 'configatron'
|
69
|
+
require 'nucleus/scripts/setup_config'
|
70
|
+
nucleus_config.logging.level = Logger::Severity::ERROR
|
71
|
+
require 'nucleus_api/scripts/load_api'
|
72
|
+
require 'nucleus_api/scripts/initialize_api'
|
73
|
+
end
|
74
|
+
|
75
|
+
task routes: :environment do
|
76
|
+
Nucleus::API::RootAPI.routes.each do |route|
|
77
|
+
next if route.nil? || route.route_method.nil?
|
78
|
+
method = route.route_method.ljust(10)
|
79
|
+
path = route.route_path
|
80
|
+
version = route.instance_variable_get(:@options)[:version]
|
81
|
+
path = path.gsub(/:version/, version) unless version.nil?
|
82
|
+
puts " #{method} #{path} - [#{version}]"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
task schema_v1: :environment do
|
87
|
+
require 'json'
|
88
|
+
response = Nucleus::API::RootAPI.call(
|
89
|
+
'REQUEST_METHOD' => 'GET',
|
90
|
+
'PATH_INFO' => '/schema',
|
91
|
+
'rack.input' => StringIO.new)[2].body[0]
|
92
|
+
json = JSON.parse(response)
|
93
|
+
puts JSON.pretty_generate(json)
|
94
|
+
end
|
95
|
+
|
96
|
+
begin
|
97
|
+
require 'yard'
|
98
|
+
DOC_FILES = %w(lib/**/*.rb).freeze
|
99
|
+
|
100
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
101
|
+
t.files = DOC_FILES
|
102
|
+
end
|
103
|
+
|
104
|
+
namespace :doc do
|
105
|
+
YARD::Rake::YardocTask.new(:pages) do |t|
|
106
|
+
t.files = DOC_FILES
|
107
|
+
t.options = ['-o', '../nucleus.doc/docs', '--title', "Nucleus #{Nucleus::VERSION} Documentation"]
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'Check out gh-pages.'
|
111
|
+
task :checkout do
|
112
|
+
dir = File.join(__dir__, '..', 'nucleus.doc')
|
113
|
+
unless Dir.exist?(dir)
|
114
|
+
Dir.mkdir(dir)
|
115
|
+
Dir.chdir(dir) do
|
116
|
+
system('git init')
|
117
|
+
system('git remote add origin git@github.com:stefan-kolb/nucleus.git')
|
118
|
+
system('git pull')
|
119
|
+
system('git checkout gh-pages')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
desc 'Generate and publish YARD docs to GitHub pages.'
|
125
|
+
task publish: %w(doc:pages:checkout doc:pages) do
|
126
|
+
Dir.chdir(File.join(__dir__, '..', 'nucleus.doc')) do
|
127
|
+
system('git checkout gh-pages')
|
128
|
+
system('git add .')
|
129
|
+
system('git add -u')
|
130
|
+
system("git commit -m 'Generating docs for version #{Nucleus::VERSION}.'")
|
131
|
+
system('git push origin gh-pages')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
rescue LoadError
|
136
|
+
puts 'You need to install YARD.'
|
137
|
+
end
|