praxis 0.10.1 → 0.11pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +47 -10
- data/Gemfile +1 -1
- data/Guardfile +1 -0
- data/bin/praxis +33 -4
- data/lib/api_browser/app/css/main.css +0 -3
- data/lib/praxis.rb +16 -0
- data/lib/praxis/action_definition.rb +16 -18
- data/lib/praxis/application.rb +31 -2
- data/lib/praxis/bootloader.rb +37 -4
- data/lib/praxis/bootloader_stages/environment.rb +3 -7
- data/lib/praxis/bootloader_stages/plugin_config_load.rb +20 -0
- data/lib/praxis/bootloader_stages/plugin_config_prepare.rb +18 -0
- data/lib/praxis/bootloader_stages/plugin_loader.rb +19 -0
- data/lib/praxis/bootloader_stages/plugin_setup.rb +13 -0
- data/lib/praxis/bootloader_stages/routing.rb +16 -6
- data/lib/praxis/callbacks.rb +0 -2
- data/lib/praxis/config.rb +3 -2
- data/lib/praxis/dispatcher.rb +25 -13
- data/lib/praxis/error_handler.rb +16 -0
- data/lib/praxis/links.rb +9 -4
- data/lib/praxis/media_type_collection.rb +2 -3
- data/lib/praxis/notifications.rb +41 -0
- data/lib/praxis/plugin.rb +18 -8
- data/lib/praxis/plugin_concern.rb +40 -0
- data/lib/praxis/request.rb +27 -7
- data/lib/praxis/request_stages/action.rb +7 -2
- data/lib/praxis/request_stages/response.rb +7 -3
- data/lib/praxis/request_stages/validate_payload.rb +7 -1
- data/lib/praxis/resource_definition.rb +37 -16
- data/lib/praxis/response.rb +1 -0
- data/lib/praxis/responses/internal_server_error.rb +13 -8
- data/lib/praxis/responses/validation_error.rb +10 -7
- data/lib/praxis/restful_doc_generator.rb +312 -0
- data/lib/praxis/router.rb +7 -5
- data/lib/praxis/skeletor/restful_routing_config.rb +12 -5
- data/lib/praxis/stage.rb +5 -1
- data/lib/praxis/stats.rb +106 -0
- data/lib/praxis/tasks/api_docs.rb +8 -314
- data/lib/praxis/version.rb +1 -1
- data/praxis.gemspec +4 -1
- data/spec/functional_spec.rb +87 -32
- data/spec/praxis/action_definition_spec.rb +13 -12
- data/spec/praxis/bootloader_spec.rb +12 -5
- data/spec/praxis/notifications_spec.rb +23 -0
- data/spec/praxis/plugin_concern_spec.rb +21 -0
- data/spec/praxis/request_spec.rb +56 -1
- data/spec/praxis/request_stages_validate_spec.rb +3 -3
- data/spec/praxis/resource_definition_spec.rb +44 -60
- data/spec/praxis/responses/internal_server_error_spec.rb +32 -16
- data/spec/praxis/restful_routing_config_spec.rb +15 -2
- data/spec/praxis/router_spec.rb +5 -3
- data/spec/praxis/stats_spec.rb +9 -0
- data/spec/praxis_mapper_plugin_spec.rb +71 -0
- data/spec/spec_app/app/controllers/instances.rb +12 -0
- data/spec/spec_app/app/controllers/volumes.rb +5 -0
- data/spec/spec_app/app/models/person.rb +3 -0
- data/spec/spec_app/config/active_record.yml +2 -0
- data/spec/spec_app/config/authentication.yml +3 -0
- data/spec/spec_app/config/authorization.yml +4 -0
- data/spec/spec_app/config/environment.rb +28 -1
- data/spec/spec_app/config/praxis_mapper.yml +6 -0
- data/spec/spec_app/config/sequel_model.yml +2 -0
- data/spec/spec_app/config/stats.yml +8 -0
- data/spec/spec_app/config/stats.yml.dis +8 -0
- data/spec/spec_app/design/resources/instances.rb +53 -16
- data/spec/spec_app/design/resources/volumes.rb +13 -2
- data/spec/spec_helper.rb +14 -0
- data/spec/support/spec_authentication_plugin.rb +126 -0
- data/spec/support/spec_authorization_plugin.rb +95 -0
- data/spec/support/spec_praxis_mapper_plugin.rb +157 -0
- data/tasks/loader.thor +6 -0
- data/tasks/thor/app.rb +48 -0
- data/tasks/thor/example.rb +283 -0
- data/tasks/thor/templates/generator/empty_app/.gitignore +3 -0
- data/tasks/thor/templates/generator/empty_app/.rspec +1 -0
- data/tasks/thor/templates/generator/empty_app/Gemfile +29 -0
- data/tasks/thor/templates/generator/empty_app/Guardfile +3 -0
- data/tasks/thor/templates/generator/empty_app/README.md +4 -0
- data/tasks/thor/templates/generator/empty_app/Rakefile +25 -0
- data/tasks/thor/templates/generator/empty_app/app/models/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/app/models/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/app/responses/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/app/responses/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/app/v1/controllers/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/app/v1/controllers/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/config.ru +7 -0
- data/tasks/thor/templates/generator/empty_app/config/environment.rb +17 -0
- data/tasks/thor/templates/generator/empty_app/config/rainbows.rb +57 -0
- data/tasks/thor/templates/generator/empty_app/design/api.rb +0 -0
- data/tasks/thor/templates/generator/empty_app/design/response_templates/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/design/response_templates/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/design/v1/media_types/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/design/v1/media_types/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/design/v1/resources/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/design/v1/resources/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/spec/spec_helper.rb +18 -0
- metadata +97 -6
- data/tasks/praxis_app_generator.thor +0 -307
@@ -0,0 +1,57 @@
|
|
1
|
+
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
|
2
|
+
# documentation.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
5
|
+
|
6
|
+
if [ 'integration', 'staging', 'production', 'meta' ].include?(ENV['RACK_ENV'])
|
7
|
+
PID_FILE = '/var/run/rainbows/rainbows.pid'
|
8
|
+
LOG_FILE = '/var/log/rails/rainbows.log'
|
9
|
+
else
|
10
|
+
PID_FILE = File.join(APP_PATH, 'rainbows.pid')
|
11
|
+
LOG_FILE = APP_PATH + "/log/rainbows.log"
|
12
|
+
end
|
13
|
+
|
14
|
+
nr_processes = (ENV['RACK_ENV'] == 'development' ? 1 : '@@RAINBOWS_WORKER_PROCESSES@@____'.to_i)
|
15
|
+
if nr_processes == 0
|
16
|
+
raise "Invalid configuration: number of rainbows workers is 0 (was RAINBOWS_WORKER_PROCESSES substituted?)"
|
17
|
+
end
|
18
|
+
|
19
|
+
Rainbows! do
|
20
|
+
worker_connections 400
|
21
|
+
keepalive_timeout 5 # zero disables keepalives entirely
|
22
|
+
client_max_body_size 5*1024*1024 # 5 megabytes
|
23
|
+
end
|
24
|
+
|
25
|
+
worker_processes nr_processes
|
26
|
+
|
27
|
+
# All production STs include an application owner field (which we assume to also be the same group)
|
28
|
+
# Thus use that user and group accordingly to run the application.
|
29
|
+
if [ 'integration', 'staging', 'production', 'meta' ].include?(ENV['RAILS_ENV'])
|
30
|
+
user('@@APPLICATION_OWNER@@','@@APPLICATION_OWNER@@')
|
31
|
+
end
|
32
|
+
|
33
|
+
# Help ensure your application will always spawn in the symlinked
|
34
|
+
# "current" directory that Capistrano sets up.
|
35
|
+
working_directory APP_PATH
|
36
|
+
|
37
|
+
stderr_path LOG_FILE
|
38
|
+
stdout_path LOG_FILE
|
39
|
+
|
40
|
+
# listen on both a Unix domain socket and a TCP port,
|
41
|
+
# we use a shorter backlog for quicker failover when busy
|
42
|
+
# listen 8080, :tcp_nopush => true
|
43
|
+
listen 8080
|
44
|
+
|
45
|
+
# PID file location
|
46
|
+
pid PID_FILE
|
47
|
+
|
48
|
+
# combine REE with "preload_app true" for memory savings
|
49
|
+
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
50
|
+
preload_app true
|
51
|
+
|
52
|
+
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
|
53
|
+
|
54
|
+
after_fork do |server, worker|
|
55
|
+
# re-establish db connections here
|
56
|
+
end
|
57
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Bundler.setup :default, :test
|
2
|
+
Bundler.require :default, :test
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.include Rack::Test::Methods
|
6
|
+
|
7
|
+
config.before(:suite) do
|
8
|
+
Praxis::Blueprint.caching_enabled = true
|
9
|
+
Praxis::Application.instance.setup
|
10
|
+
end
|
11
|
+
|
12
|
+
config.before(:each) do
|
13
|
+
Praxis::Blueprint.cache = Hash.new do |hash, key|
|
14
|
+
hash[key] = Hash.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: praxis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Blanquer
|
@@ -115,14 +115,14 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 2.3.0
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 2.3.0
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: thor
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +137,34 @@ dependencies:
|
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: terminal-table
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '1.4'
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '1.4'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: harness
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '2'
|
161
|
+
type: :runtime
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '2'
|
140
168
|
- !ruby/object:Gem::Dependency
|
141
169
|
name: bundler
|
142
170
|
requirement: !ruby/object:Gem::Requirement
|
@@ -361,6 +389,20 @@ dependencies:
|
|
361
389
|
- - "~>"
|
362
390
|
- !ruby/object:Gem::Version
|
363
391
|
version: '0'
|
392
|
+
- !ruby/object:Gem::Dependency
|
393
|
+
name: sqlite3
|
394
|
+
requirement: !ruby/object:Gem::Requirement
|
395
|
+
requirements:
|
396
|
+
- - "~>"
|
397
|
+
- !ruby/object:Gem::Version
|
398
|
+
version: '1'
|
399
|
+
type: :development
|
400
|
+
prerelease: false
|
401
|
+
version_requirements: !ruby/object:Gem::Requirement
|
402
|
+
requirements:
|
403
|
+
- - "~>"
|
404
|
+
- !ruby/object:Gem::Version
|
405
|
+
version: '1'
|
364
406
|
description:
|
365
407
|
email:
|
366
408
|
- blanquer@gmail.com
|
@@ -763,6 +805,10 @@ files:
|
|
763
805
|
- lib/praxis/bootloader.rb
|
764
806
|
- lib/praxis/bootloader_stages/environment.rb
|
765
807
|
- lib/praxis/bootloader_stages/file_loader.rb
|
808
|
+
- lib/praxis/bootloader_stages/plugin_config_load.rb
|
809
|
+
- lib/praxis/bootloader_stages/plugin_config_prepare.rb
|
810
|
+
- lib/praxis/bootloader_stages/plugin_loader.rb
|
811
|
+
- lib/praxis/bootloader_stages/plugin_setup.rb
|
766
812
|
- lib/praxis/bootloader_stages/routing.rb
|
767
813
|
- lib/praxis/bootloader_stages/subgroup_loader.rb
|
768
814
|
- lib/praxis/bootloader_stages/warn_unloaded_files.rb
|
@@ -771,6 +817,7 @@ files:
|
|
771
817
|
- lib/praxis/content_type_parser.rb
|
772
818
|
- lib/praxis/controller.rb
|
773
819
|
- lib/praxis/dispatcher.rb
|
820
|
+
- lib/praxis/error_handler.rb
|
774
821
|
- lib/praxis/exception.rb
|
775
822
|
- lib/praxis/exceptions/config.rb
|
776
823
|
- lib/praxis/exceptions/config_load.rb
|
@@ -786,7 +833,9 @@ files:
|
|
786
833
|
- lib/praxis/media_type_collection.rb
|
787
834
|
- lib/praxis/multipart/parser.rb
|
788
835
|
- lib/praxis/multipart/part.rb
|
836
|
+
- lib/praxis/notifications.rb
|
789
837
|
- lib/praxis/plugin.rb
|
838
|
+
- lib/praxis/plugin_concern.rb
|
790
839
|
- lib/praxis/request.rb
|
791
840
|
- lib/praxis/request_stages/action.rb
|
792
841
|
- lib/praxis/request_stages/load_request.rb
|
@@ -802,11 +851,13 @@ files:
|
|
802
851
|
- lib/praxis/responses/http.rb
|
803
852
|
- lib/praxis/responses/internal_server_error.rb
|
804
853
|
- lib/praxis/responses/validation_error.rb
|
854
|
+
- lib/praxis/restful_doc_generator.rb
|
805
855
|
- lib/praxis/route.rb
|
806
856
|
- lib/praxis/router.rb
|
807
857
|
- lib/praxis/simple_media_type.rb
|
808
858
|
- lib/praxis/skeletor/restful_routing_config.rb
|
809
859
|
- lib/praxis/stage.rb
|
860
|
+
- lib/praxis/stats.rb
|
810
861
|
- lib/praxis/tasks.rb
|
811
862
|
- lib/praxis/tasks/api_docs.rb
|
812
863
|
- lib/praxis/tasks/console.rb
|
@@ -831,6 +882,8 @@ files:
|
|
831
882
|
- spec/praxis/media_type_collection_spec.rb
|
832
883
|
- spec/praxis/media_type_spec.rb
|
833
884
|
- spec/praxis/multipart/parser_spec.rb
|
885
|
+
- spec/praxis/notifications_spec.rb
|
886
|
+
- spec/praxis/plugin_concern_spec.rb
|
834
887
|
- spec/praxis/request_spec.rb
|
835
888
|
- spec/praxis/request_stage_spec.rb
|
836
889
|
- spec/praxis/request_stages_action_spec.rb
|
@@ -844,18 +897,28 @@ files:
|
|
844
897
|
- spec/praxis/route_spec.rb
|
845
898
|
- spec/praxis/router_spec.rb
|
846
899
|
- spec/praxis/stage_spec.rb
|
900
|
+
- spec/praxis/stats_spec.rb
|
847
901
|
- spec/praxis/types/multipart_spec.rb
|
902
|
+
- spec/praxis_mapper_plugin_spec.rb
|
848
903
|
- spec/spec_app/app/concerns/authenticated.rb
|
849
904
|
- spec/spec_app/app/concerns/basic_api.rb
|
850
905
|
- spec/spec_app/app/concerns/log_wrapper.rb
|
851
906
|
- spec/spec_app/app/controllers/base_class.rb
|
852
907
|
- spec/spec_app/app/controllers/instances.rb
|
853
908
|
- spec/spec_app/app/controllers/volumes.rb
|
909
|
+
- spec/spec_app/app/models/person.rb
|
854
910
|
- spec/spec_app/app/responses/bulk_response.rb
|
855
911
|
- spec/spec_app/app/responses/multipart.rb
|
856
912
|
- spec/spec_app/app/responses/other_response.rb
|
857
913
|
- spec/spec_app/config.ru
|
914
|
+
- spec/spec_app/config/active_record.yml
|
915
|
+
- spec/spec_app/config/authentication.yml
|
916
|
+
- spec/spec_app/config/authorization.yml
|
858
917
|
- spec/spec_app/config/environment.rb
|
918
|
+
- spec/spec_app/config/praxis_mapper.yml
|
919
|
+
- spec/spec_app/config/sequel_model.yml
|
920
|
+
- spec/spec_app/config/stats.yml
|
921
|
+
- spec/spec_app/config/stats.yml.dis
|
859
922
|
- spec/spec_app/design/api.rb
|
860
923
|
- spec/spec_app/design/media_types/instance.rb
|
861
924
|
- spec/spec_app/design/media_types/volume.rb
|
@@ -863,9 +926,37 @@ files:
|
|
863
926
|
- spec/spec_app/design/resources/instances.rb
|
864
927
|
- spec/spec_app/design/resources/volumes.rb
|
865
928
|
- spec/spec_helper.rb
|
929
|
+
- spec/support/spec_authentication_plugin.rb
|
930
|
+
- spec/support/spec_authorization_plugin.rb
|
866
931
|
- spec/support/spec_media_types.rb
|
932
|
+
- spec/support/spec_praxis_mapper_plugin.rb
|
867
933
|
- spec/support/spec_resource_definitions.rb
|
868
|
-
- tasks/
|
934
|
+
- tasks/loader.thor
|
935
|
+
- tasks/thor/app.rb
|
936
|
+
- tasks/thor/example.rb
|
937
|
+
- tasks/thor/templates/generator/empty_app/.gitignore
|
938
|
+
- tasks/thor/templates/generator/empty_app/.rspec
|
939
|
+
- tasks/thor/templates/generator/empty_app/Gemfile
|
940
|
+
- tasks/thor/templates/generator/empty_app/Guardfile
|
941
|
+
- tasks/thor/templates/generator/empty_app/README.md
|
942
|
+
- tasks/thor/templates/generator/empty_app/Rakefile
|
943
|
+
- tasks/thor/templates/generator/empty_app/app/models/.empty_directory
|
944
|
+
- tasks/thor/templates/generator/empty_app/app/models/.gitkeep
|
945
|
+
- tasks/thor/templates/generator/empty_app/app/responses/.empty_directory
|
946
|
+
- tasks/thor/templates/generator/empty_app/app/responses/.gitkeep
|
947
|
+
- tasks/thor/templates/generator/empty_app/app/v1/controllers/.empty_directory
|
948
|
+
- tasks/thor/templates/generator/empty_app/app/v1/controllers/.gitkeep
|
949
|
+
- tasks/thor/templates/generator/empty_app/config.ru
|
950
|
+
- tasks/thor/templates/generator/empty_app/config/environment.rb
|
951
|
+
- tasks/thor/templates/generator/empty_app/config/rainbows.rb
|
952
|
+
- tasks/thor/templates/generator/empty_app/design/api.rb
|
953
|
+
- tasks/thor/templates/generator/empty_app/design/response_templates/.empty_directory
|
954
|
+
- tasks/thor/templates/generator/empty_app/design/response_templates/.gitkeep
|
955
|
+
- tasks/thor/templates/generator/empty_app/design/v1/media_types/.empty_directory
|
956
|
+
- tasks/thor/templates/generator/empty_app/design/v1/media_types/.gitkeep
|
957
|
+
- tasks/thor/templates/generator/empty_app/design/v1/resources/.empty_directory
|
958
|
+
- tasks/thor/templates/generator/empty_app/design/v1/resources/.gitkeep
|
959
|
+
- tasks/thor/templates/generator/empty_app/spec/spec_helper.rb
|
869
960
|
homepage: https://github.com/rightscale/praxis
|
870
961
|
licenses:
|
871
962
|
- MIT
|
@@ -881,9 +972,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
881
972
|
version: '2.1'
|
882
973
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
883
974
|
requirements:
|
884
|
-
- - "
|
975
|
+
- - ">"
|
885
976
|
- !ruby/object:Gem::Version
|
886
|
-
version:
|
977
|
+
version: 1.3.1
|
887
978
|
requirements: []
|
888
979
|
rubyforge_project:
|
889
980
|
rubygems_version: 2.2.2
|
@@ -1,307 +0,0 @@
|
|
1
|
-
# vim: setlocal filetype=ruby:
|
2
|
-
|
3
|
-
require 'thor'
|
4
|
-
require 'pathname'
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
# Praxis application generator
|
8
|
-
#
|
9
|
-
# Generates all files required to run a simple praxis app.
|
10
|
-
#
|
11
|
-
class PraxisAppGenerator < Thor
|
12
|
-
include Thor::Actions
|
13
|
-
|
14
|
-
attr_reader :app_name
|
15
|
-
|
16
|
-
namespace 'praxis'
|
17
|
-
desc "generate 'app-name'", "Generates a new PRAXIS application"
|
18
|
-
|
19
|
-
# Generates a new praxis app in the current directory
|
20
|
-
#
|
21
|
-
# @param [String] name
|
22
|
-
#
|
23
|
-
# @return [void]
|
24
|
-
#
|
25
|
-
# @example
|
26
|
-
# # Using thor task
|
27
|
-
# > bundle exec thor generate my_test_app
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# # Using 'praxis' file saved into '/usr/bin'
|
31
|
-
# > praxis generate my_test_app
|
32
|
-
#
|
33
|
-
def generate(app_name)
|
34
|
-
# Fix weird symbols in the app name (if they are)
|
35
|
-
@app_name = app_name.downcase.gsub(/[^a-z0-9_\/.]/, '')
|
36
|
-
# Generate a new app
|
37
|
-
empty_directory path('app')
|
38
|
-
empty_directory path('design')
|
39
|
-
empty_directory path('lib')
|
40
|
-
empty_directory path('spec')
|
41
|
-
generate_config_environment_rb
|
42
|
-
generate_gemfile
|
43
|
-
generate_rakefile
|
44
|
-
generate_config_ru
|
45
|
-
generate_app_definitions_hello_world
|
46
|
-
generate_app_controllers_hello_world
|
47
|
-
#
|
48
|
-
puts
|
49
|
-
puts "To run the example application:"
|
50
|
-
puts
|
51
|
-
puts " # terminal 1:"
|
52
|
-
puts " cd #{app_name}"
|
53
|
-
puts " bundle"
|
54
|
-
puts " rackup -p 8888"
|
55
|
-
puts
|
56
|
-
puts " # terminal 2:"
|
57
|
-
puts " curl -i http://localhost:8888/api/hello -H 'X-Api-Version: 1.0' -X GET # Index"
|
58
|
-
puts " curl -i http://localhost:8888/api/hello/2 -H 'X-Api-Version: 1.0' -X GET # Show"
|
59
|
-
puts " curl -i http://localhost:8888/api/hello/2 -H 'X-Api-Version: 2.0' -X GET # NotFound Error"
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
|
67
|
-
# Returns relative path for the new application
|
68
|
-
#
|
69
|
-
# @return [String]
|
70
|
-
#
|
71
|
-
# @example
|
72
|
-
# # > /praxis generate My-test_praxisApp
|
73
|
-
# app_dir_pathname #=> 'mytest_praxisapp'
|
74
|
-
#
|
75
|
-
#
|
76
|
-
def app_dir_pathname
|
77
|
-
@app_dir_pathname ||= Pathname.new(app_name)
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
# Returns path string built from the set of the given strings
|
82
|
-
#
|
83
|
-
# @param [String,Array] strings
|
84
|
-
#
|
85
|
-
# @return [String]
|
86
|
-
#
|
87
|
-
# @example
|
88
|
-
# path('a', 'b', 'c') #=> 'my_test_app/a/b/c'
|
89
|
-
#
|
90
|
-
def path(*strings)
|
91
|
-
app_dir_pathname.join(*strings).to_s
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
# Creates './config/environment.rb' file
|
96
|
-
#
|
97
|
-
# @return [void]
|
98
|
-
#
|
99
|
-
def generate_config_environment_rb
|
100
|
-
create_file path('config/environment.rb') do
|
101
|
-
<<-RUBY
|
102
|
-
# Main entry point - DO NOT MODIFY THIS FILE
|
103
|
-
ENV['RACK_ENV'] ||= 'development'
|
104
|
-
|
105
|
-
Bundler.require(:default, ENV['RACK_ENV'])
|
106
|
-
|
107
|
-
# Default application layout.
|
108
|
-
# NOTE: This layout need NOT be specified explicitly.
|
109
|
-
# It is provided just for illustration.
|
110
|
-
Praxis::Application.instance.layout do
|
111
|
-
map :initializers, 'config/initializers/**/*'
|
112
|
-
map :lib, 'lib/**/*'
|
113
|
-
map :design, 'design/' do
|
114
|
-
map :api, 'api.rb'
|
115
|
-
map :media_types, '**/media_types/**/*'
|
116
|
-
map :resources, '**/resources/**/*'
|
117
|
-
end
|
118
|
-
map :app, 'app/' do
|
119
|
-
map :models, 'models/**/*'
|
120
|
-
map :controllers, '**/controllers/**/*'
|
121
|
-
map :responses, '**/responses/**/*'
|
122
|
-
end
|
123
|
-
end
|
124
|
-
RUBY
|
125
|
-
end
|
126
|
-
nil
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
# Creates './Gemfile' file
|
131
|
-
#
|
132
|
-
# @return [void]
|
133
|
-
#
|
134
|
-
def generate_gemfile
|
135
|
-
create_file path('Gemfile') do
|
136
|
-
<<-RUBY
|
137
|
-
source 'https://rubygems.org'
|
138
|
-
|
139
|
-
gem 'praxis'
|
140
|
-
gem 'rack', '~> 1.0'
|
141
|
-
gem 'rake'
|
142
|
-
|
143
|
-
group :development, :test do
|
144
|
-
gem 'rspec'
|
145
|
-
end
|
146
|
-
RUBY
|
147
|
-
end
|
148
|
-
nil
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
# Creates './Rakefile' file
|
153
|
-
#
|
154
|
-
# @return [void]
|
155
|
-
#
|
156
|
-
def generate_rakefile
|
157
|
-
create_file path('Rakefile') do
|
158
|
-
<<-RUBY
|
159
|
-
require 'praxis'
|
160
|
-
require 'praxis/tasks'
|
161
|
-
RUBY
|
162
|
-
end
|
163
|
-
nil
|
164
|
-
end
|
165
|
-
|
166
|
-
|
167
|
-
# Creates './config.ru' file
|
168
|
-
#
|
169
|
-
# @return [void]
|
170
|
-
#
|
171
|
-
def generate_config_ru
|
172
|
-
create_file path('config.ru') do
|
173
|
-
<<-RUBY
|
174
|
-
#\ -p 8888
|
175
|
-
|
176
|
-
require 'bundler/setup'
|
177
|
-
require 'praxis'
|
178
|
-
|
179
|
-
application = Praxis::Application.instance
|
180
|
-
application.logger = Logger.new(STDOUT)
|
181
|
-
application.setup
|
182
|
-
|
183
|
-
run application
|
184
|
-
RUBY
|
185
|
-
end
|
186
|
-
nil
|
187
|
-
end
|
188
|
-
|
189
|
-
|
190
|
-
def generate_app_definitions_hello_world
|
191
|
-
create_file path('design/api.rb') do
|
192
|
-
<<-RUBY
|
193
|
-
# Use this file to define your response templates and traits.
|
194
|
-
#
|
195
|
-
# For example, to define a response template:
|
196
|
-
# response_template :custom do |media_type:|
|
197
|
-
# status 200
|
198
|
-
# media_type media_type
|
199
|
-
# end
|
200
|
-
Praxis::ApiDefinition.define do
|
201
|
-
trait :versionable do
|
202
|
-
headers do
|
203
|
-
key "X-Api-Version", String, values: ['1.0'], required: true
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
RUBY
|
208
|
-
end
|
209
|
-
|
210
|
-
create_file path('design/resources/hello.rb') do
|
211
|
-
<<-RUBY
|
212
|
-
module V1
|
213
|
-
module ApiResources
|
214
|
-
class Hello
|
215
|
-
include Praxis::ResourceDefinition
|
216
|
-
|
217
|
-
media_type V1::MediaTypes::Hello
|
218
|
-
version '1.0'
|
219
|
-
|
220
|
-
routing do
|
221
|
-
prefix '/api/hello'
|
222
|
-
end
|
223
|
-
|
224
|
-
action :index do
|
225
|
-
use :versionable
|
226
|
-
|
227
|
-
routing do
|
228
|
-
get ''
|
229
|
-
end
|
230
|
-
response :ok
|
231
|
-
end
|
232
|
-
|
233
|
-
action :show do
|
234
|
-
use :versionable
|
235
|
-
|
236
|
-
routing do
|
237
|
-
get '/:id'
|
238
|
-
end
|
239
|
-
params do
|
240
|
-
attribute :id, Integer, required: true, min: 0
|
241
|
-
end
|
242
|
-
response :ok
|
243
|
-
response :not_found
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
RUBY
|
249
|
-
end
|
250
|
-
|
251
|
-
create_file path('design/media_types/hello.rb') do
|
252
|
-
<<-RUBY
|
253
|
-
module V1
|
254
|
-
module MediaTypes
|
255
|
-
class Hello < Praxis::MediaType
|
256
|
-
|
257
|
-
identifier 'application/json'
|
258
|
-
|
259
|
-
attributes do
|
260
|
-
attribute :string, String
|
261
|
-
end
|
262
|
-
|
263
|
-
view :default do
|
264
|
-
attribute :string
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
RUBY
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
|
274
|
-
def generate_app_controllers_hello_world
|
275
|
-
create_file path('app/controllers/hello.rb') do
|
276
|
-
<<-RUBY
|
277
|
-
module V1
|
278
|
-
class Hello
|
279
|
-
include Praxis::Controller
|
280
|
-
|
281
|
-
implements V1::ApiResources::Hello
|
282
|
-
|
283
|
-
HELLO_WORLD = [ 'Hello world!', 'Привет мир!', 'Hola mundo!', '你好世界!', 'こんにちは世界!' ]
|
284
|
-
|
285
|
-
def index(**params)
|
286
|
-
response.headers['Content-Type'] = 'application/json'
|
287
|
-
response.body = HELLO_WORLD.to_json
|
288
|
-
response
|
289
|
-
end
|
290
|
-
|
291
|
-
def show(id:, **other_params)
|
292
|
-
hello = HELLO_WORLD[id]
|
293
|
-
if hello
|
294
|
-
response.body = { id: id, data: hello }
|
295
|
-
else
|
296
|
-
self.response = Praxis::Responses::NotFound.new
|
297
|
-
end
|
298
|
-
response.headers['Content-Type'] = 'application/json'
|
299
|
-
response
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
RUBY
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
end
|