trailblazer-endpoint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +3 -0
  3. data/Gemfile +16 -0
  4. data/README.md +11 -0
  5. data/Rakefile +10 -0
  6. data/lib/trailblazer-endpoint.rb +1 -0
  7. data/lib/trailblazer/endpoint.rb +133 -0
  8. data/lib/trailblazer/endpoint/adapter.rb +197 -0
  9. data/lib/trailblazer/endpoint/builder.rb +56 -0
  10. data/lib/trailblazer/endpoint/protocol.rb +122 -0
  11. data/lib/trailblazer/endpoint/rails.rb +27 -0
  12. data/lib/trailblazer/endpoint/version.rb +5 -0
  13. data/test/adapter/api_test.rb +78 -0
  14. data/test/adapter/representable_test.rb +7 -0
  15. data/test/adapter/web_test.rb +40 -0
  16. data/test/benchmark/skill_resolver_benchmark.rb +43 -0
  17. data/test/docs/controller_test.rb +92 -0
  18. data/test/docs/endpoint_test.rb +54 -0
  19. data/test/endpoint_test.rb +908 -0
  20. data/test/rails-app/.gitignore +21 -0
  21. data/test/rails-app/Gemfile +17 -0
  22. data/test/rails-app/Gemfile.lock +157 -0
  23. data/test/rails-app/README.md +24 -0
  24. data/test/rails-app/Rakefile +6 -0
  25. data/test/rails-app/app/controllers/application_controller.rb +3 -0
  26. data/test/rails-app/app/controllers/songs_controller.rb +26 -0
  27. data/test/rails-app/app/models/application_record.rb +3 -0
  28. data/test/rails-app/app/models/concerns/.keep +0 -0
  29. data/test/rails-app/config.ru +5 -0
  30. data/test/rails-app/config/application.rb +15 -0
  31. data/test/rails-app/config/boot.rb +3 -0
  32. data/test/rails-app/config/database.yml +25 -0
  33. data/test/rails-app/config/environment.rb +5 -0
  34. data/test/rails-app/config/environments/development.rb +54 -0
  35. data/test/rails-app/config/environments/production.rb +86 -0
  36. data/test/rails-app/config/environments/test.rb +42 -0
  37. data/test/rails-app/config/initializers/application_controller_renderer.rb +6 -0
  38. data/test/rails-app/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/rails-app/config/initializers/cookies_serializer.rb +5 -0
  40. data/test/rails-app/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/test/rails-app/config/initializers/inflections.rb +16 -0
  42. data/test/rails-app/config/initializers/mime_types.rb +4 -0
  43. data/test/rails-app/config/initializers/new_framework_defaults.rb +24 -0
  44. data/test/rails-app/config/initializers/session_store.rb +3 -0
  45. data/test/rails-app/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/rails-app/config/locales/en.yml +23 -0
  47. data/test/rails-app/config/routes.rb +6 -0
  48. data/test/rails-app/config/secrets.yml +22 -0
  49. data/test/rails-app/db/seeds.rb +7 -0
  50. data/test/rails-app/log/.keep +0 -0
  51. data/test/rails-app/test/controllers/.keep +0 -0
  52. data/test/rails-app/test/controllers/songs_controller_test.rb +156 -0
  53. data/test/rails-app/test/fixtures/.keep +0 -0
  54. data/test/rails-app/test/fixtures/files/.keep +0 -0
  55. data/test/rails-app/test/helpers/.keep +0 -0
  56. data/test/rails-app/test/integration/.keep +0 -0
  57. data/test/rails-app/test/mailers/.keep +0 -0
  58. data/test/rails-app/test/models/.keep +0 -0
  59. data/test/rails-app/test/test_helper.rb +10 -0
  60. data/test/rails-app/tmp/.keep +0 -0
  61. data/test/rails-app/vendor/assets/javascripts/.keep +0 -0
  62. data/test/rails-app/vendor/assets/stylesheets/.keep +0 -0
  63. data/test/test_helper.rb +34 -0
  64. data/trailblazer-endpoint.gemspec +26 -0
  65. metadata +236 -0
@@ -0,0 +1,21 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # Ignore Byebug command history file.
21
+ .byebug_history
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
+ gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
6
+ # Use sqlite3 as the database for Active Record
7
+ gem 'sqlite3'
8
+
9
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
10
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
11
+
12
+ gem "trailblazer-endpoint", path: "../../."
13
+ gem "trailblazer", path: "../../../trailblazer"
14
+ gem "trailblazer-operation", path: "../../../operation"
15
+ # gem "trailblazer-rails"
16
+
17
+ gem "multi_json"
@@ -0,0 +1,157 @@
1
+ PATH
2
+ remote: ../../../operation
3
+ specs:
4
+ trailblazer-operation (0.0.6)
5
+ declarative
6
+ pipetree (>= 0.0.4, < 0.1.0)
7
+ uber (>= 0.1.0, < 0.2.0)
8
+
9
+ PATH
10
+ remote: ../../../trailblazer
11
+ specs:
12
+ trailblazer (2.0.0.beta1)
13
+ declarative
14
+ reform (>= 2.2.0, < 3.0.0)
15
+ trailblazer-operation
16
+ uber (>= 0.1.0, < 0.2.0)
17
+
18
+ PATH
19
+ remote: ../../.
20
+ specs:
21
+ trailblazer-endpoint (0.0.1)
22
+ dry-matcher
23
+
24
+ GEM
25
+ remote: https://rubygems.org/
26
+ specs:
27
+ actioncable (5.0.0.1)
28
+ actionpack (= 5.0.0.1)
29
+ nio4r (~> 1.2)
30
+ websocket-driver (~> 0.6.1)
31
+ actionmailer (5.0.0.1)
32
+ actionpack (= 5.0.0.1)
33
+ actionview (= 5.0.0.1)
34
+ activejob (= 5.0.0.1)
35
+ mail (~> 2.5, >= 2.5.4)
36
+ rails-dom-testing (~> 2.0)
37
+ actionpack (5.0.0.1)
38
+ actionview (= 5.0.0.1)
39
+ activesupport (= 5.0.0.1)
40
+ rack (~> 2.0)
41
+ rack-test (~> 0.6.3)
42
+ rails-dom-testing (~> 2.0)
43
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
44
+ actionview (5.0.0.1)
45
+ activesupport (= 5.0.0.1)
46
+ builder (~> 3.1)
47
+ erubis (~> 2.7.0)
48
+ rails-dom-testing (~> 2.0)
49
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
50
+ activejob (5.0.0.1)
51
+ activesupport (= 5.0.0.1)
52
+ globalid (>= 0.3.6)
53
+ activemodel (5.0.0.1)
54
+ activesupport (= 5.0.0.1)
55
+ activerecord (5.0.0.1)
56
+ activemodel (= 5.0.0.1)
57
+ activesupport (= 5.0.0.1)
58
+ arel (~> 7.0)
59
+ activesupport (5.0.0.1)
60
+ concurrent-ruby (~> 1.0, >= 1.0.2)
61
+ i18n (~> 0.7)
62
+ minitest (~> 5.1)
63
+ tzinfo (~> 1.1)
64
+ arel (7.1.4)
65
+ builder (3.2.2)
66
+ concurrent-ruby (1.0.2)
67
+ declarative (0.0.8)
68
+ uber (>= 0.0.15)
69
+ disposable (0.3.2)
70
+ declarative (>= 0.0.8, < 1.0.0)
71
+ representable (>= 2.4.0, <= 3.1.0)
72
+ uber
73
+ dry-matcher (0.5.0)
74
+ erubis (2.7.0)
75
+ globalid (0.3.7)
76
+ activesupport (>= 4.1.0)
77
+ i18n (0.7.0)
78
+ loofah (2.0.3)
79
+ nokogiri (>= 1.5.9)
80
+ mail (2.6.4)
81
+ mime-types (>= 1.16, < 4)
82
+ method_source (0.8.2)
83
+ mime-types (3.1)
84
+ mime-types-data (~> 3.2015)
85
+ mime-types-data (3.2016.0521)
86
+ mini_portile2 (2.1.0)
87
+ minitest (5.9.1)
88
+ multi_json (1.12.1)
89
+ nio4r (1.2.1)
90
+ nokogiri (1.6.8.1)
91
+ mini_portile2 (~> 2.1.0)
92
+ pipetree (0.0.4)
93
+ rack (2.0.1)
94
+ rack-test (0.6.3)
95
+ rack (>= 1.0)
96
+ rails (5.0.0.1)
97
+ actioncable (= 5.0.0.1)
98
+ actionmailer (= 5.0.0.1)
99
+ actionpack (= 5.0.0.1)
100
+ actionview (= 5.0.0.1)
101
+ activejob (= 5.0.0.1)
102
+ activemodel (= 5.0.0.1)
103
+ activerecord (= 5.0.0.1)
104
+ activesupport (= 5.0.0.1)
105
+ bundler (>= 1.3.0, < 2.0)
106
+ railties (= 5.0.0.1)
107
+ sprockets-rails (>= 2.0.0)
108
+ rails-dom-testing (2.0.1)
109
+ activesupport (>= 4.2.0, < 6.0)
110
+ nokogiri (~> 1.6.0)
111
+ rails-html-sanitizer (1.0.3)
112
+ loofah (~> 2.0)
113
+ railties (5.0.0.1)
114
+ actionpack (= 5.0.0.1)
115
+ activesupport (= 5.0.0.1)
116
+ method_source
117
+ rake (>= 0.8.7)
118
+ thor (>= 0.18.1, < 2.0)
119
+ rake (11.3.0)
120
+ reform (2.2.3)
121
+ disposable (>= 0.3.0, < 0.4.0)
122
+ representable (>= 2.4.0, < 3.1.0)
123
+ uber (>= 0.0.15, < 0.2.0)
124
+ representable (3.0.2)
125
+ declarative (~> 0.0.5)
126
+ uber (>= 0.0.15, < 0.2.0)
127
+ sprockets (3.7.0)
128
+ concurrent-ruby (~> 1.0)
129
+ rack (> 1, < 3)
130
+ sprockets-rails (3.2.0)
131
+ actionpack (>= 4.0)
132
+ activesupport (>= 4.0)
133
+ sprockets (>= 3.0.0)
134
+ sqlite3 (1.3.12)
135
+ thor (0.19.1)
136
+ thread_safe (0.3.5)
137
+ tzinfo (1.2.2)
138
+ thread_safe (~> 0.1)
139
+ uber (0.1.0)
140
+ websocket-driver (0.6.4)
141
+ websocket-extensions (>= 0.1.0)
142
+ websocket-extensions (0.1.2)
143
+
144
+ PLATFORMS
145
+ ruby
146
+
147
+ DEPENDENCIES
148
+ multi_json
149
+ rails (~> 5.0.0, >= 5.0.0.1)
150
+ sqlite3
151
+ trailblazer!
152
+ trailblazer-endpoint!
153
+ trailblazer-operation!
154
+ tzinfo-data
155
+
156
+ BUNDLED WITH
157
+ 1.12.5
@@ -0,0 +1,24 @@
1
+ # README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,26 @@
1
+ class SongsController < ApplicationController
2
+ require "trailblazer/endpoint/rails"
3
+ include Trailblazer::Endpoint::Controller
4
+
5
+ def create
6
+ endpoint Create, path: songs_path, args: [ params, { "user.current" => ::Module } ]
7
+ end
8
+
9
+ def update
10
+ endpoint Update, path: songs_path, args: [params]
11
+ end
12
+
13
+ def update_with_user
14
+ endpoint Update, path: songs_path, args: [ params, { "user.current" => ::Module } ]
15
+ end
16
+
17
+ def show
18
+ endpoint Show, path: songs_path, args: [ params, { "user.current" => ::Module } ]
19
+ end
20
+
21
+ def create_with_custom_handlers
22
+ endpoint Create, path: songs_path, args: [ params, { "user.current" => ::Module } ] do |m|
23
+ m.created { |result| render json: result["representer.serializer.class"].new(result["model"]), status: 999 }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,15 @@
1
+ require_relative 'boot'
2
+
3
+ require 'rails/all'
4
+
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(*Rails.groups)
8
+
9
+ module RailsApp
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,54 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable/disable caching. By default caching is disabled.
16
+ if Rails.root.join('tmp/caching-dev.txt').exist?
17
+ config.action_controller.perform_caching = true
18
+
19
+ config.cache_store = :memory_store
20
+ config.public_file_server.headers = {
21
+ 'Cache-Control' => 'public, max-age=172800'
22
+ }
23
+ else
24
+ config.action_controller.perform_caching = false
25
+
26
+ config.cache_store = :null_store
27
+ end
28
+
29
+ # Don't care if the mailer can't send.
30
+ config.action_mailer.raise_delivery_errors = false
31
+
32
+ config.action_mailer.perform_caching = false
33
+
34
+ # Print deprecation notices to the Rails logger.
35
+ config.active_support.deprecation = :log
36
+
37
+ # Raise an error on page load if there are pending migrations.
38
+ config.active_record.migration_error = :page_load
39
+
40
+ # Debug mode disables concatenation and preprocessing of assets.
41
+ # This option may cause significant delays in view rendering with a large
42
+ # number of complex assets.
43
+ config.assets.debug = true
44
+
45
+ # Suppress logger output for asset requests.
46
+ config.assets.quiet = true
47
+
48
+ # Raises error for missing translations
49
+ # config.action_view.raise_on_missing_translations = true
50
+
51
+ # Use an evented file watcher to asynchronously detect changes in source code,
52
+ # routes, locales, etc. This feature depends on the listen gem.
53
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
54
+ end
@@ -0,0 +1,86 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Disable serving static files from the `/public` folder by default since
18
+ # Apache or NGINX already handles this.
19
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
20
+
21
+ # Compress JavaScripts and CSS.
22
+ config.assets.js_compressor = :uglifier
23
+ # config.assets.css_compressor = :sass
24
+
25
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
26
+ config.assets.compile = false
27
+
28
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
29
+
30
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
31
+ # config.action_controller.asset_host = 'http://assets.example.com'
32
+
33
+ # Specifies the header that your server uses for sending files.
34
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
35
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
36
+
37
+ # Mount Action Cable outside main process or domain
38
+ # config.action_cable.mount_path = nil
39
+ # config.action_cable.url = 'wss://example.com/cable'
40
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
41
+
42
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43
+ # config.force_ssl = true
44
+
45
+ # Use the lowest log level to ensure availability of diagnostic information
46
+ # when problems arise.
47
+ config.log_level = :debug
48
+
49
+ # Prepend all log lines with the following tags.
50
+ config.log_tags = [ :request_id ]
51
+
52
+ # Use a different cache store in production.
53
+ # config.cache_store = :mem_cache_store
54
+
55
+ # Use a real queuing backend for Active Job (and separate queues per environment)
56
+ # config.active_job.queue_adapter = :resque
57
+ # config.active_job.queue_name_prefix = "rails-app_#{Rails.env}"
58
+ config.action_mailer.perform_caching = false
59
+
60
+ # Ignore bad email addresses and do not raise email delivery errors.
61
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
62
+ # config.action_mailer.raise_delivery_errors = false
63
+
64
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
65
+ # the I18n.default_locale when a translation cannot be found).
66
+ config.i18n.fallbacks = true
67
+
68
+ # Send deprecation notices to registered listeners.
69
+ config.active_support.deprecation = :notify
70
+
71
+ # Use default logging formatter so that PID and timestamp are not suppressed.
72
+ config.log_formatter = ::Logger::Formatter.new
73
+
74
+ # Use a different logger for distributed setups.
75
+ # require 'syslog/logger'
76
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
77
+
78
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
79
+ logger = ActiveSupport::Logger.new(STDOUT)
80
+ logger.formatter = config.log_formatter
81
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
82
+ end
83
+
84
+ # Do not dump schema after migrations.
85
+ config.active_record.dump_schema_after_migration = false
86
+ end