graphiti 1.0.rc.21 → 1.0.rc.22
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 +5 -5
- data/.gitignore +1 -0
- data/.standard.yml +14 -0
- data/.travis.yml +31 -2
- data/Appraisals +16 -10
- data/Gemfile +5 -5
- data/Guardfile +2 -2
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/exe/graphiti +1 -1
- data/gemfiles/rails_4.gemfile +0 -1
- data/gemfiles/rails_5.gemfile +0 -1
- data/gemfiles/rails_6.gemfile +19 -0
- data/graphiti.gemspec +15 -14
- data/lib/generators/graphiti/api_test_generator.rb +16 -16
- data/lib/generators/graphiti/generator_mixin.rb +7 -7
- data/lib/generators/graphiti/install_generator.rb +19 -19
- data/lib/generators/graphiti/resource_generator.rb +19 -19
- data/lib/generators/graphiti/resource_test_generator.rb +10 -10
- data/lib/graphiti.rb +24 -26
- data/lib/graphiti/adapters/abstract.rb +25 -39
- data/lib/graphiti/adapters/active_record.rb +43 -49
- data/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +33 -11
- data/lib/graphiti/adapters/graphiti_api.rb +16 -16
- data/lib/graphiti/adapters/null.rb +0 -12
- data/lib/graphiti/cli.rb +7 -7
- data/lib/graphiti/configuration.rb +14 -15
- data/lib/graphiti/context.rb +1 -1
- data/lib/graphiti/debugger.rb +22 -26
- data/lib/graphiti/delegates/pagination.rb +9 -9
- data/lib/graphiti/deserializer.rb +7 -9
- data/lib/graphiti/errors.rb +119 -119
- data/lib/graphiti/extensions/boolean_attribute.rb +1 -1
- data/lib/graphiti/extensions/extra_attribute.rb +1 -1
- data/lib/graphiti/extensions/temp_id.rb +1 -1
- data/lib/graphiti/filter_operators.rb +6 -0
- data/lib/graphiti/hash_renderer.rb +15 -15
- data/lib/graphiti/jsonapi_serializable_ext.rb +1 -1
- data/lib/graphiti/query.rb +35 -35
- data/lib/graphiti/railtie.rb +14 -10
- data/lib/graphiti/renderer.rb +2 -2
- data/lib/graphiti/resource.rb +4 -6
- data/lib/graphiti/resource/configuration.rb +9 -13
- data/lib/graphiti/resource/documentation.rb +4 -2
- data/lib/graphiti/resource/dsl.rb +21 -25
- data/lib/graphiti/resource/interface.rb +3 -3
- data/lib/graphiti/resource/links.rb +14 -14
- data/lib/graphiti/resource/persistence.rb +9 -9
- data/lib/graphiti/resource/polymorphism.rb +3 -3
- data/lib/graphiti/resource/remote.rb +3 -3
- data/lib/graphiti/resource/sideloading.rb +5 -5
- data/lib/graphiti/resource_proxy.rb +12 -12
- data/lib/graphiti/schema.rb +27 -26
- data/lib/graphiti/schema_diff.rb +10 -10
- data/lib/graphiti/scope.rb +12 -16
- data/lib/graphiti/scoping/base.rb +5 -5
- data/lib/graphiti/scoping/default_filter.rb +1 -1
- data/lib/graphiti/scoping/filter.rb +15 -24
- data/lib/graphiti/scoping/filterable.rb +5 -5
- data/lib/graphiti/scoping/paginate.rb +1 -1
- data/lib/graphiti/scoping/sort.rb +7 -7
- data/lib/graphiti/serializer.rb +8 -4
- data/lib/graphiti/sideload.rb +23 -39
- data/lib/graphiti/sideload/belongs_to.rb +2 -2
- data/lib/graphiti/sideload/has_many.rb +1 -1
- data/lib/graphiti/sideload/many_to_many.rb +18 -2
- data/lib/graphiti/sideload/polymorphic_belongs_to.rb +14 -8
- data/lib/graphiti/stats/dsl.rb +7 -1
- data/lib/graphiti/tasks.rb +10 -10
- data/lib/graphiti/types.rb +98 -98
- data/lib/graphiti/util/attribute_check.rb +1 -1
- data/lib/graphiti/util/class.rb +3 -3
- data/lib/graphiti/util/field_params.rb +1 -1
- data/lib/graphiti/util/hash.rb +19 -1
- data/lib/graphiti/util/link.rb +15 -19
- data/lib/graphiti/util/persistence.rb +17 -22
- data/lib/graphiti/util/relationship_payload.rb +2 -2
- data/lib/graphiti/util/remote_params.rb +12 -12
- data/lib/graphiti/util/remote_serializer.rb +2 -2
- data/lib/graphiti/util/serializer_attributes.rb +20 -25
- data/lib/graphiti/util/serializer_relationships.rb +17 -18
- data/lib/graphiti/util/sideload.rb +1 -1
- data/lib/graphiti/util/transaction_hooks_recorder.rb +3 -2
- data/lib/graphiti/version.rb +1 -1
- metadata +22 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: d213472a51c9849c856ba5742132b6298ca17b47
|
|
4
|
+
data.tar.gz: 81201cada6bf3cf2e0c566495eb46f343acf0932
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f98bbcbb4a61d7e783e4a651a66843bd3e74c3418002069917be3f564e596a202bc6eb2c72049a89ec7f2608f60c07e44da1447d8b93605c6e5fd5ffa244fbab
|
|
7
|
+
data.tar.gz: 3754a4e800e735ac54496f808d0e5cfedd1b2bd35e939086a14c02acdca46b61fbfa5bf9c2b587224e399301d9cda32fdc0709f6d80b772d8735f789821b576a
|
data/.gitignore
CHANGED
data/.standard.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
fix: true
|
|
2
|
+
parallel: true
|
|
3
|
+
ruby_version: 2.4
|
|
4
|
+
|
|
5
|
+
ignore:
|
|
6
|
+
- 'vendor/**/*'
|
|
7
|
+
- 'spec/**/*':
|
|
8
|
+
# There are some false hits when doing repeated
|
|
9
|
+
# Class.new blocks in different test cases
|
|
10
|
+
- Lint/DuplicateMethods
|
|
11
|
+
# This was causing many tests to be harder to read.
|
|
12
|
+
# Ongoing discussion with StandardRB team in
|
|
13
|
+
# https://github.com/testdouble/standard/issues/94
|
|
14
|
+
- Standard/SemanticBlocks
|
data/.travis.yml
CHANGED
|
@@ -4,8 +4,37 @@ rvm:
|
|
|
4
4
|
- 2.4
|
|
5
5
|
- 2.5
|
|
6
6
|
- 2.6
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
gemfile:
|
|
8
|
+
- Gemfile
|
|
9
|
+
- gemfiles/rails_4.gemfile
|
|
10
|
+
- gemfiles/rails_5.gemfile
|
|
11
|
+
- gemfiles/rails_6.gemfile
|
|
12
|
+
env:
|
|
13
|
+
- COMMAND=standardrb --no-fix --format progress
|
|
14
|
+
- COMMAND=rspec
|
|
15
|
+
- COMMAND=rspec APPRAISAL_INITIALIZED=true
|
|
16
|
+
matrix:
|
|
17
|
+
exclude:
|
|
18
|
+
- env: COMMAND=standardrb --no-fix --format progress
|
|
19
|
+
gemfile: gemfiles/rails_4.gemfile
|
|
20
|
+
- env: COMMAND=standardrb --no-fix --format progress
|
|
21
|
+
gemfile: gemfiles/rails_5.gemfile
|
|
22
|
+
- env: COMMAND=standardrb --no-fix --format progress
|
|
23
|
+
gemfile: gemfiles/rails_6.gemfile
|
|
24
|
+
- env: COMMAND=rspec APPRAISAL_INITIALIZED=true
|
|
25
|
+
gemfile: Gemfile
|
|
26
|
+
- env: COMMAND=rspec
|
|
27
|
+
gemfile: gemfiles/rails_4.gemfile
|
|
28
|
+
- env: COMMAND=rspec
|
|
29
|
+
gemfile: gemfiles/rails_5.gemfile
|
|
30
|
+
- env: COMMAND=rspec
|
|
31
|
+
gemfile: gemfiles/rails_6.gemfile
|
|
32
|
+
- gemfile: gemfiles/rails_6.gemfile
|
|
33
|
+
rvm: 2.4
|
|
34
|
+
|
|
35
|
+
script:
|
|
36
|
+
- bundle exec $COMMAND
|
|
37
|
+
|
|
9
38
|
install: bundle install --retry=3 --jobs=3
|
|
10
39
|
before_install:
|
|
11
40
|
- gem install bundler -v '< 2'
|
data/Appraisals
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
appraise "rails-4" do
|
|
2
2
|
gem "rails", "~> 4.1"
|
|
3
|
-
gem
|
|
4
|
-
gem
|
|
5
|
-
gem
|
|
6
|
-
gem
|
|
7
|
-
gem 'kaminari', '~> 0.17'
|
|
3
|
+
gem "rspec-rails"
|
|
4
|
+
gem "sqlite3", "~> 1.3.6"
|
|
5
|
+
gem "database_cleaner"
|
|
6
|
+
gem "kaminari", "~> 0.17"
|
|
8
7
|
end
|
|
9
8
|
|
|
10
9
|
appraise "rails-5" do
|
|
11
10
|
gem "rails", "~> 5.2"
|
|
12
|
-
gem
|
|
13
|
-
gem
|
|
14
|
-
gem
|
|
15
|
-
gem
|
|
16
|
-
|
|
11
|
+
gem "rspec-rails"
|
|
12
|
+
gem "sqlite3", "~> 1.3.6"
|
|
13
|
+
gem "database_cleaner"
|
|
14
|
+
gem "kaminari", "~> 0.17"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
appraise "rails-6" do
|
|
18
|
+
gem "rails", "~> 6.0.0.beta2"
|
|
19
|
+
gem "rspec-rails"
|
|
20
|
+
gem "sqlite3", "~> 1.3.6"
|
|
21
|
+
gem "database_cleaner"
|
|
22
|
+
gem "kaminari", "~> 0.17"
|
|
17
23
|
end
|
data/Gemfile
CHANGED
|
@@ -4,9 +4,9 @@ source "https://rubygems.org"
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
group :test do
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
9
|
-
gem
|
|
10
|
-
gem
|
|
11
|
-
gem
|
|
7
|
+
gem "pry"
|
|
8
|
+
gem "pry-byebug", platform: [:mri]
|
|
9
|
+
gem "appraisal"
|
|
10
|
+
gem "guard"
|
|
11
|
+
gem "guard-rspec"
|
|
12
12
|
end
|
data/Guardfile
CHANGED
|
@@ -16,12 +16,12 @@ guard :rspec, cmd: "bundle exec rspec --color --format documentation" do
|
|
|
16
16
|
dsl.watch_spec_files_for(ruby.lib_files)
|
|
17
17
|
|
|
18
18
|
# Rails files
|
|
19
|
-
rails = dsl.rails(view_extensions: %w
|
|
19
|
+
rails = dsl.rails(view_extensions: %w[erb haml slim])
|
|
20
20
|
|
|
21
21
|
watch(rails.controllers) do |m|
|
|
22
22
|
[
|
|
23
23
|
rspec.spec.call("controllers/#{m[1]}_controller"),
|
|
24
|
-
rspec.spec.call("api/#{m[1]}")
|
|
24
|
+
rspec.spec.call("api/#{m[1]}"),
|
|
25
25
|
]
|
|
26
26
|
end
|
|
27
27
|
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Stylish Graph APIs.
|
|
6
6
|
|
|
7
|
-
[View Official Documentation](https://graphiti
|
|
7
|
+
[View Official Documentation](https://www.graphiti.dev/guides/)
|
|
8
8
|
|
|
9
9
|
[Join the Slack Channel](https://join.slack.com/t/graphiti-api/shared_invite/enQtMjkyMTA3MDgxNTQzLWVkMDM3NTlmNTIwODY2YWFkMGNiNzUzZGMzOTY3YmNmZjBhYzIyZWZlZTk4YmI1YTI0Y2M0OTZmZGYwN2QxZjg)
|
|
10
10
|
|
data/Rakefile
CHANGED
|
@@ -4,12 +4,12 @@ require "appraisal"
|
|
|
4
4
|
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
6
6
|
if ENV["APPRAISAL_INITIALIZED"]
|
|
7
|
-
t.pattern =
|
|
7
|
+
t.pattern = "spec/integration/rails"
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
if !ENV["APPRAISAL_INITIALIZED"] && !ENV[
|
|
12
|
-
task :
|
|
11
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
|
12
|
+
task default: [:spec, :appraisal]
|
|
13
13
|
else
|
|
14
|
-
task :
|
|
14
|
+
task default: [:spec]
|
|
15
15
|
end
|
data/exe/graphiti
CHANGED
data/gemfiles/rails_4.gemfile
CHANGED
data/gemfiles/rails_5.gemfile
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "rails", "~> 6.0.0.beta2"
|
|
6
|
+
gem "rspec-rails"
|
|
7
|
+
gem "sqlite3", "~> 1.3.6"
|
|
8
|
+
gem "database_cleaner"
|
|
9
|
+
gem "kaminari", "~> 0.17"
|
|
10
|
+
|
|
11
|
+
group :test do
|
|
12
|
+
gem "pry"
|
|
13
|
+
gem "pry-byebug", platform: [:mri]
|
|
14
|
+
gem "appraisal"
|
|
15
|
+
gem "guard"
|
|
16
|
+
gem "guard-rspec"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
gemspec path: "../"
|
data/graphiti.gemspec
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require
|
|
3
|
+
require "graphiti/version"
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
6
|
spec.name = "graphiti"
|
|
@@ -9,26 +8,28 @@ Gem::Specification.new do |spec|
|
|
|
9
8
|
spec.authors = ["Lee Richmond"]
|
|
10
9
|
spec.email = ["richmolj@gmail.com"]
|
|
11
10
|
|
|
12
|
-
spec.summary =
|
|
11
|
+
spec.summary = "Easily build jsonapi.org-compatible APIs"
|
|
12
|
+
spec.homepage = "https://github.com/graphiti-api/graphiti"
|
|
13
13
|
spec.license = "MIT"
|
|
14
14
|
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
16
16
|
spec.bindir = "exe"
|
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
18
18
|
spec.require_paths = ["lib"]
|
|
19
|
-
spec.required_ruby_version =
|
|
19
|
+
spec.required_ruby_version = "~> 2.3"
|
|
20
20
|
|
|
21
21
|
# Pinning this version until backwards-incompatibility is addressed
|
|
22
|
-
spec.add_dependency
|
|
23
|
-
spec.add_dependency
|
|
24
|
-
spec.add_dependency
|
|
25
|
-
spec.add_dependency
|
|
26
|
-
spec.add_dependency
|
|
22
|
+
spec.add_dependency "jsonapi-serializable", "= 0.3.0"
|
|
23
|
+
spec.add_dependency "dry-types", "~> 0.13"
|
|
24
|
+
spec.add_dependency "graphiti_errors", "~> 1.0.beta.1"
|
|
25
|
+
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
|
26
|
+
spec.add_dependency "activesupport", [">= 4.1", "< 6"]
|
|
27
27
|
|
|
28
|
-
spec.add_development_dependency "faraday",
|
|
29
|
-
spec.add_development_dependency "kaminari",
|
|
28
|
+
spec.add_development_dependency "faraday", "~> 0.15"
|
|
29
|
+
spec.add_development_dependency "kaminari", "~> 0.17"
|
|
30
30
|
spec.add_development_dependency "bundler"
|
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
32
|
-
spec.add_development_dependency "activemodel", [
|
|
33
|
-
spec.add_development_dependency "graphiti_spec_helpers",
|
|
32
|
+
spec.add_development_dependency "activemodel", [">= 4.1", "< 6"]
|
|
33
|
+
spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
|
|
34
|
+
spec.add_development_dependency "standard"
|
|
34
35
|
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
|
2
|
-
require
|
|
2
|
+
require "generator_mixin"
|
|
3
3
|
|
|
4
4
|
module Graphiti
|
|
5
5
|
class ApiTestGenerator < ::Rails::Generators::Base
|
|
6
6
|
include GeneratorMixin
|
|
7
7
|
|
|
8
|
-
source_root File.expand_path(
|
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
9
9
|
|
|
10
10
|
argument :resource, type: :string
|
|
11
|
-
class_option :
|
|
11
|
+
class_option :actions,
|
|
12
12
|
type: :array,
|
|
13
13
|
default: nil,
|
|
14
|
-
aliases: [
|
|
14
|
+
aliases: ["--actions", "-a"],
|
|
15
15
|
desc: 'Array of controller actions, e.g. "index show destroy"'
|
|
16
16
|
|
|
17
|
-
desc
|
|
17
|
+
desc "Generates rspec request specs at spec/api"
|
|
18
18
|
def generate
|
|
19
19
|
generate_api_specs
|
|
20
20
|
end
|
|
@@ -26,33 +26,33 @@ module Graphiti
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def dir
|
|
29
|
-
@resource.gsub(
|
|
29
|
+
@resource.gsub("Resource", "").underscore.pluralize
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def generate_api_specs
|
|
33
|
-
if actions?(
|
|
33
|
+
if actions?("index")
|
|
34
34
|
to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "index_spec.rb")
|
|
35
|
-
template(
|
|
35
|
+
template("index_request_spec.rb.erb", to)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
if actions?(
|
|
38
|
+
if actions?("show")
|
|
39
39
|
to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "show_spec.rb")
|
|
40
|
-
template(
|
|
40
|
+
template("show_request_spec.rb.erb", to)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
if actions?(
|
|
43
|
+
if actions?("create")
|
|
44
44
|
to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "create_spec.rb")
|
|
45
|
-
template(
|
|
45
|
+
template("create_request_spec.rb.erb", to)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
if actions?(
|
|
48
|
+
if actions?("update")
|
|
49
49
|
to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "update_spec.rb")
|
|
50
|
-
template(
|
|
50
|
+
template("update_request_spec.rb.erb", to)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
if actions?(
|
|
53
|
+
if actions?("destroy")
|
|
54
54
|
to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "destroy_spec.rb")
|
|
55
|
-
template(
|
|
55
|
+
template("destroy_request_spec.rb.erb", to)
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -4,21 +4,21 @@ module Graphiti
|
|
|
4
4
|
say(set_color("\n#{header}", :magenta, :bold)) if header
|
|
5
5
|
say("\n#{description}") if description
|
|
6
6
|
answer = ask(set_color("\n(default: #{default}):", :magenta, :bold))
|
|
7
|
-
answer = default if answer.blank? && default !=
|
|
7
|
+
answer = default if answer.blank? && default != "nil"
|
|
8
8
|
say(set_color("\nGot it!\n", :white, :bold))
|
|
9
9
|
answer
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def api_namespace
|
|
13
13
|
@api_namespace ||= begin
|
|
14
|
-
ns = graphiti_config[
|
|
14
|
+
ns = graphiti_config["namespace"]
|
|
15
15
|
|
|
16
16
|
if ns.blank?
|
|
17
17
|
ns = prompt \
|
|
18
18
|
header: "What is your API namespace?",
|
|
19
19
|
description: "This will be used as a route prefix, e.g. if you want the route '/books_api/v1/authors' your namespace would be '/books_api/v1'",
|
|
20
|
-
default:
|
|
21
|
-
update_config!(
|
|
20
|
+
default: "/api/v1"
|
|
21
|
+
update_config!("namespace" => ns)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
ns
|
|
@@ -26,7 +26,7 @@ module Graphiti
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def actions
|
|
29
|
-
@options[
|
|
29
|
+
@options["actions"] || %w[index show create update destroy]
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def actions?(*methods)
|
|
@@ -34,12 +34,12 @@ module Graphiti
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def graphiti_config
|
|
37
|
-
File.
|
|
37
|
+
File.exist?(".graphiticfg.yml") ? YAML.load_file(".graphiticfg.yml") : {}
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def update_config!(attrs)
|
|
41
41
|
config = graphiti_config.merge(attrs)
|
|
42
|
-
File.open(
|
|
42
|
+
File.open(".graphiticfg.yml", "w") { |f| f.write(config.to_yaml) }
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
|
2
|
-
require
|
|
2
|
+
require "generator_mixin"
|
|
3
3
|
|
|
4
4
|
module Graphiti
|
|
5
5
|
class InstallGenerator < ::Rails::Generators::Base
|
|
6
6
|
include GeneratorMixin
|
|
7
7
|
|
|
8
|
-
source_root File.expand_path(
|
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
9
9
|
|
|
10
10
|
class_option :'omit-comments',
|
|
11
11
|
type: :boolean,
|
|
12
12
|
default: false,
|
|
13
|
-
aliases: [
|
|
14
|
-
desc:
|
|
13
|
+
aliases: ["-c"],
|
|
14
|
+
desc: "Generate without documentation comments"
|
|
15
15
|
|
|
16
16
|
desc "This generator boostraps graphiti"
|
|
17
17
|
def install
|
|
18
|
-
to = File.join(
|
|
19
|
-
template(
|
|
18
|
+
to = File.join("app/resources", "application_resource.rb")
|
|
19
|
+
template("application_resource.rb.erb", to)
|
|
20
20
|
|
|
21
|
-
inject_into_file
|
|
21
|
+
inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::API\n" do
|
|
22
22
|
app_controller_code
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
inject_into_file
|
|
25
|
+
inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
|
|
26
26
|
app_controller_code
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
inject_into_file
|
|
30
|
-
<<-'RUBY'
|
|
29
|
+
inject_into_file "config/application.rb", after: "Rails::Application\n" do
|
|
30
|
+
<<-'RUBY'
|
|
31
31
|
# In order for Graphiti to generate links, you need to set the routes host.
|
|
32
32
|
# When not explicitly set, via the HOST env var, this will fall back to
|
|
33
33
|
# the rails server settings.
|
|
@@ -39,27 +39,27 @@ module Graphiti
|
|
|
39
39
|
"http://#{argv_options[:Host]}:#{argv_options[:Port]}"
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
-
RUBY
|
|
42
|
+
RUBY
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
inject_into_file
|
|
46
|
-
"\n\nGraphitiSpecHelpers::RSpec.schema!"
|
|
45
|
+
inject_into_file "spec/rails_helper.rb", after: /RSpec.configure.+^end$/m do
|
|
46
|
+
"\n\nGraphitiSpecHelpers::RSpec.schema!"
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
insert_into_file "config/routes.rb", :
|
|
49
|
+
insert_into_file "config/routes.rb", after: "Rails.application.routes.draw do\n" do
|
|
50
50
|
if defined?(VandalUi)
|
|
51
|
-
|
|
51
|
+
<<-STR
|
|
52
52
|
scope path: ApplicationResource.endpoint_namespace, defaults: { format: :jsonapi } do
|
|
53
53
|
mount VandalUi::Engine, at: '/vandal'
|
|
54
54
|
# your routes go here
|
|
55
55
|
end
|
|
56
|
-
|
|
56
|
+
STR
|
|
57
57
|
else
|
|
58
|
-
|
|
58
|
+
<<-STR
|
|
59
59
|
scope path: ApplicationResource.endpoint_namespace, defaults: { format: :jsonapi } do
|
|
60
60
|
# your routes go here
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
STR
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -67,7 +67,7 @@ RUBY
|
|
|
67
67
|
private
|
|
68
68
|
|
|
69
69
|
def omit_comments?
|
|
70
|
-
@options[
|
|
70
|
+
@options["omit-comments"]
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def app_controller_code
|