praxis 2.0.pre.9 → 2.0.pre.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +11 -0
- data/TODO.md +1 -4
- data/bin/praxis +11 -13
- data/lib/praxis.rb +10 -3
- data/lib/praxis/action_definition.rb +15 -13
- data/lib/praxis/action_definition/headers_dsl_compiler.rb +0 -7
- data/lib/praxis/api_general_info.rb +1 -1
- data/lib/praxis/application.rb +6 -2
- data/lib/praxis/blueprint.rb +357 -0
- data/lib/praxis/bootloader.rb +9 -3
- data/lib/praxis/bootloader_stages/environment.rb +15 -13
- data/lib/praxis/collection.rb +1 -11
- data/lib/praxis/config_hash.rb +44 -0
- data/lib/praxis/docs/{openapi → open_api}/info_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/media_type_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/operation_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/parameter_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/paths_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/request_body_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/response_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/responses_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/schema_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/server_object.rb +0 -0
- data/lib/praxis/docs/{openapi → open_api}/tag_object.rb +0 -0
- data/lib/praxis/docs/open_api_generator.rb +90 -5
- data/lib/praxis/endpoint_definition.rb +273 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +1 -1
- data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +1 -1
- data/lib/praxis/extensions/field_expansion.rb +3 -36
- data/lib/praxis/extensions/pagination.rb +2 -2
- data/lib/praxis/extensions/pagination/ordering_params.rb +1 -1
- data/lib/praxis/extensions/pagination/pagination_params.rb +6 -4
- data/lib/praxis/field_expander.rb +90 -0
- data/lib/praxis/finalizable.rb +34 -0
- data/lib/praxis/mapper/selector_generator.rb +1 -1
- data/lib/praxis/media_type.rb +3 -68
- data/lib/praxis/plugin_concern.rb +1 -1
- data/lib/praxis/plugins/mapper_plugin.rb +7 -7
- data/lib/praxis/renderer.rb +88 -0
- data/lib/praxis/request.rb +1 -1
- data/lib/praxis/resource_definition.rb +2 -311
- data/lib/praxis/response_definition.rb +2 -10
- data/lib/praxis/response_template.rb +3 -3
- data/lib/praxis/router.rb +2 -2
- data/lib/praxis/routing_config.rb +1 -1
- data/lib/praxis/tasks/api_docs.rb +13 -63
- data/lib/praxis/tasks/routes.rb +1 -1
- data/lib/praxis/types/media_type_common.rb +1 -11
- data/lib/praxis/version.rb +1 -1
- data/praxis.gemspec +0 -1
- data/spec/functional_spec.rb +5 -9
- data/spec/praxis/action_definition_spec.rb +12 -20
- data/spec/praxis/blueprint_spec.rb +373 -0
- data/spec/praxis/bootloader_spec.rb +10 -2
- data/spec/praxis/collection_spec.rb +0 -13
- data/spec/praxis/config_hash_spec.rb +64 -0
- data/spec/praxis/{resource_definition_spec.rb → endpoint_definition_spec.rb} +37 -64
- data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +4 -6
- data/spec/praxis/extensions/field_expansion_spec.rb +5 -24
- data/spec/praxis/field_expander_spec.rb +149 -0
- data/spec/praxis/media_type_identifier_spec.rb +5 -4
- data/spec/praxis/media_type_spec.rb +4 -93
- data/spec/praxis/renderer_spec.rb +188 -0
- data/spec/praxis/response_definition_spec.rb +0 -31
- data/spec/praxis/response_spec.rb +1 -1
- data/spec/praxis/router_spec.rb +8 -8
- data/spec/praxis/routing_config_spec.rb +3 -3
- data/spec/spec_app/app/controllers/instances.rb +13 -7
- data/spec/spec_app/design/media_types/instance.rb +1 -19
- data/spec/spec_app/design/media_types/volume.rb +1 -1
- data/spec/spec_app/design/media_types/volume_snapshot.rb +2 -14
- data/spec/spec_app/design/resources/instances.rb +5 -8
- data/spec/spec_app/design/resources/volume_snapshots.rb +1 -1
- data/spec/spec_app/design/resources/volumes.rb +1 -1
- data/spec/support/spec_authorization_plugin.rb +1 -1
- data/spec/support/spec_blueprints.rb +72 -0
- data/spec/support/{spec_resource_definitions.rb → spec_endpoint_definitions.rb} +2 -2
- data/spec/support/spec_media_types.rb +6 -26
- data/tasks/thor/app.rb +8 -34
- data/tasks/thor/example.rb +45 -285
- data/tasks/thor/templates/generator/empty_app/.gitignore +0 -1
- data/tasks/thor/templates/generator/empty_app/Gemfile +7 -23
- data/tasks/thor/templates/generator/empty_app/README.md +1 -1
- data/tasks/thor/templates/generator/empty_app/Rakefile +4 -13
- data/tasks/thor/templates/generator/empty_app/{design/response_templates → app/v1/resources}/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/{design/response_templates → app/v1/resources}/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/config/environment.rb +25 -17
- data/tasks/thor/templates/generator/empty_app/{design/v1/resources → config/initializers}/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/{design/v1/resources → config/initializers}/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/design/v1/endpoints/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/design/v1/endpoints/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/docs/.empty_directory +0 -0
- data/tasks/thor/templates/generator/empty_app/docs/.gitkeep +0 -0
- data/tasks/thor/templates/generator/empty_app/spec/spec_helper.rb +14 -9
- data/tasks/thor/templates/generator/example_app/.gitignore +1 -0
- data/tasks/thor/templates/generator/example_app/Gemfile +19 -0
- data/tasks/thor/templates/generator/example_app/Rakefile +54 -0
- data/tasks/thor/templates/generator/example_app/app/models/user.rb +6 -0
- data/tasks/thor/templates/generator/example_app/app/v1/controllers/users.rb +17 -0
- data/tasks/thor/templates/generator/example_app/app/v1/resources/user.rb +46 -0
- data/tasks/thor/templates/generator/example_app/config.ru +31 -0
- data/tasks/thor/templates/generator/example_app/config/environment.rb +40 -0
- data/tasks/thor/templates/generator/example_app/db/migrate/20201010101010_create_users_table.rb +11 -0
- data/tasks/thor/templates/generator/example_app/design/api.rb +18 -0
- data/tasks/thor/templates/generator/example_app/design/v1/endpoints/users.rb +37 -0
- data/tasks/thor/templates/generator/example_app/design/v1/media_types/user.rb +26 -0
- data/tasks/thor/templates/generator/example_app/spec/helpers/database_helper.rb +18 -0
- data/tasks/thor/templates/generator/example_app/spec/spec_helper.rb +42 -0
- data/tasks/thor/templates/generator/example_app/spec/v1/controllers/users_spec.rb +37 -0
- metadata +49 -135
- data/lib/api_browser/.bowerrc +0 -3
- data/lib/api_browser/.editorconfig +0 -21
- data/lib/api_browser/Gruntfile.js +0 -581
- data/lib/api_browser/app/index.html +0 -59
- data/lib/api_browser/app/js/app.js +0 -48
- data/lib/api_browser/app/js/controllers/action.js +0 -47
- data/lib/api_browser/app/js/controllers/controller.js +0 -10
- data/lib/api_browser/app/js/controllers/menu.js +0 -93
- data/lib/api_browser/app/js/controllers/trait.js +0 -10
- data/lib/api_browser/app/js/controllers/type.js +0 -24
- data/lib/api_browser/app/js/directives/attribute_description.js +0 -56
- data/lib/api_browser/app/js/directives/attribute_table.js +0 -28
- data/lib/api_browser/app/js/directives/conditional_requirements.js +0 -13
- data/lib/api_browser/app/js/directives/fixed_if_fits.js +0 -38
- data/lib/api_browser/app/js/directives/highlight.js +0 -14
- data/lib/api_browser/app/js/directives/menu_item.js +0 -59
- data/lib/api_browser/app/js/directives/no_container.js +0 -8
- data/lib/api_browser/app/js/directives/readable_list.js +0 -87
- data/lib/api_browser/app/js/directives/request_examples.js +0 -31
- data/lib/api_browser/app/js/directives/type_placeholder.js +0 -30
- data/lib/api_browser/app/js/directives/url.js +0 -15
- data/lib/api_browser/app/js/factories/Configuration.js +0 -12
- data/lib/api_browser/app/js/factories/Documentation.js +0 -61
- data/lib/api_browser/app/js/factories/Example.js +0 -51
- data/lib/api_browser/app/js/factories/PageInfo.js +0 -9
- data/lib/api_browser/app/js/factories/normalize_attributes.js +0 -20
- data/lib/api_browser/app/js/factories/prepare_template.js +0 -15
- data/lib/api_browser/app/js/factories/template_for.js +0 -128
- data/lib/api_browser/app/js/filters/attribute_name.js +0 -10
- data/lib/api_browser/app/js/filters/friendly_json.js +0 -5
- data/lib/api_browser/app/js/filters/has_requirement.js +0 -14
- data/lib/api_browser/app/js/filters/header_info.js +0 -9
- data/lib/api_browser/app/js/filters/is_empty.js +0 -8
- data/lib/api_browser/app/js/filters/markdown.js +0 -6
- data/lib/api_browser/app/js/filters/resource_name.js +0 -5
- data/lib/api_browser/app/js/filters/tag_requirement.js +0 -13
- data/lib/api_browser/app/sass/modules/_body.scss +0 -40
- data/lib/api_browser/app/sass/modules/_cloke.scss +0 -8
- data/lib/api_browser/app/sass/modules/_header.scss +0 -10
- data/lib/api_browser/app/sass/modules/_nav.scss +0 -7
- data/lib/api_browser/app/sass/modules/_sidebar.scss +0 -134
- data/lib/api_browser/app/sass/modules/_switch.scss +0 -55
- data/lib/api_browser/app/sass/modules/_table.scss +0 -13
- data/lib/api_browser/app/sass/praxis.scss +0 -70
- data/lib/api_browser/app/sass/variables/_bootstrap-variables.scss +0 -774
- data/lib/api_browser/app/views/action.html +0 -97
- data/lib/api_browser/app/views/builtin/field-selector.html +0 -24
- data/lib/api_browser/app/views/controller.html +0 -55
- data/lib/api_browser/app/views/directives/attribute_description.html +0 -2
- data/lib/api_browser/app/views/directives/attribute_description/default.html +0 -2
- data/lib/api_browser/app/views/directives/attribute_description/example.html +0 -13
- data/lib/api_browser/app/views/directives/attribute_description/headers.html +0 -8
- data/lib/api_browser/app/views/directives/attribute_description/member_options.html +0 -4
- data/lib/api_browser/app/views/directives/attribute_description/values.html +0 -14
- data/lib/api_browser/app/views/directives/attribute_table.html +0 -17
- data/lib/api_browser/app/views/directives/menu_item.html +0 -8
- data/lib/api_browser/app/views/directives/url.html +0 -3
- data/lib/api_browser/app/views/examples/general.html +0 -26
- data/lib/api_browser/app/views/home.html +0 -5
- data/lib/api_browser/app/views/layout.html +0 -8
- data/lib/api_browser/app/views/menu.html +0 -42
- data/lib/api_browser/app/views/navbar.html +0 -9
- data/lib/api_browser/app/views/trait.html +0 -13
- data/lib/api_browser/app/views/type.html +0 -6
- data/lib/api_browser/app/views/type/details.html +0 -33
- data/lib/api_browser/app/views/types/embedded/array.html +0 -2
- data/lib/api_browser/app/views/types/embedded/default.html +0 -12
- data/lib/api_browser/app/views/types/embedded/field-selector.html +0 -13
- data/lib/api_browser/app/views/types/embedded/links.html +0 -11
- data/lib/api_browser/app/views/types/embedded/requirements.html +0 -6
- data/lib/api_browser/app/views/types/embedded/single_req.html +0 -9
- data/lib/api_browser/app/views/types/embedded/struct.html +0 -14
- data/lib/api_browser/app/views/types/label/link.html +0 -1
- data/lib/api_browser/app/views/types/label/primitive.html +0 -1
- data/lib/api_browser/app/views/types/label/primitive_collection.html +0 -1
- data/lib/api_browser/app/views/types/label/type.html +0 -1
- data/lib/api_browser/app/views/types/label/type_collection.html +0 -1
- data/lib/api_browser/app/views/types/main/array.html +0 -22
- data/lib/api_browser/app/views/types/main/default.html +0 -23
- data/lib/api_browser/app/views/types/main/hash.html +0 -23
- data/lib/api_browser/app/views/types/standalone/array.html +0 -3
- data/lib/api_browser/app/views/types/standalone/default.html +0 -18
- data/lib/api_browser/app/views/types/standalone/struct.html +0 -2
- data/lib/api_browser/bower_template.json +0 -41
- data/lib/api_browser/package-lock.json +0 -7110
- data/lib/api_browser/package.json +0 -43
- data/lib/praxis/docs/generator.rb +0 -243
- data/lib/praxis/docs/link_builder.rb +0 -30
- data/lib/praxis/links.rb +0 -135
- data/lib/praxis/types/multipart.rb +0 -109
- data/spec/api_browser/directives/type_placeholder_spec.js +0 -134
- data/spec/api_browser/factories/configuration_spec.js +0 -32
- data/spec/api_browser/factories/documentation_spec.js +0 -100
- data/spec/api_browser/factories/normalize_attributes_spec.js +0 -92
- data/spec/api_browser/factories/template_for_spec.js +0 -67
- data/spec/api_browser/filters/attribute_name_spec.js +0 -23
- data/spec/praxis/types/multipart_spec.rb +0 -112
- data/tasks/thor/templates/generator/empty_app/.rspec +0 -1
- data/tasks/thor/templates/generator/empty_app/Guardfile +0 -3
- data/tasks/thor/templates/generator/empty_app/config/rainbows.rb +0 -57
- data/tasks/thor/templates/generator/empty_app/docs/app.js +0 -1
- data/tasks/thor/templates/generator/empty_app/docs/styles.scss +0 -3
@@ -16,26 +16,8 @@ class Instance < Praxis::MediaType
|
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
default_fieldset do
|
20
20
|
attribute :id
|
21
21
|
attribute :root_volume
|
22
22
|
end
|
23
|
-
|
24
|
-
view :link do
|
25
|
-
attribute :id
|
26
|
-
attribute :href
|
27
|
-
end
|
28
|
-
|
29
|
-
view :create do
|
30
|
-
attribute :id
|
31
|
-
attribute :name
|
32
|
-
end
|
33
|
-
|
34
|
-
view :extended, include_nil: true do
|
35
|
-
attribute :id
|
36
|
-
attribute :name
|
37
|
-
attribute :root_volume
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
23
|
end
|
@@ -6,16 +6,11 @@ class VolumeSnapshot < Praxis::MediaType
|
|
6
6
|
attribute :name, String, regexp: /snapshot-(\w+)/
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
default_fieldset do
|
10
10
|
attribute :id
|
11
11
|
attribute :name
|
12
12
|
end
|
13
13
|
|
14
|
-
view :link do
|
15
|
-
attribute :id
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
14
|
class CollectionSummary < Praxis::MediaType
|
20
15
|
identifier 'application/json'
|
21
16
|
|
@@ -25,18 +20,11 @@ class VolumeSnapshot < Praxis::MediaType
|
|
25
20
|
attribute :href, String
|
26
21
|
end
|
27
22
|
|
28
|
-
|
29
|
-
attribute :name
|
30
|
-
attribute :size
|
31
|
-
attribute :href
|
32
|
-
end
|
33
|
-
|
34
|
-
view :link do
|
23
|
+
default_fieldset do
|
35
24
|
attribute :name
|
36
25
|
attribute :size
|
37
26
|
attribute :href
|
38
27
|
end
|
39
|
-
|
40
28
|
end
|
41
29
|
|
42
30
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ApiResources
|
2
2
|
class Instances
|
3
|
-
include Praxis::
|
3
|
+
include Praxis::EndpointDefinition
|
4
4
|
|
5
5
|
media_type Instance
|
6
6
|
version '1.0'
|
@@ -119,13 +119,10 @@ module ApiResources
|
|
119
119
|
attribute :id
|
120
120
|
end
|
121
121
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
key 'file', Attributor::FileUpload, required: false
|
127
|
-
extra 'options'
|
128
|
-
end
|
122
|
+
payload Praxis::Types::MultipartArray do
|
123
|
+
part 'destination_path', String, required: true
|
124
|
+
file 'file', Attributor::Tempfile, required: false
|
125
|
+
part(/.*/, String) # Allows extra parts
|
129
126
|
end
|
130
127
|
|
131
128
|
response :ok, media_type: 'application/json'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class PersonBlueprint < Praxis::Blueprint
|
3
|
+
attributes do
|
4
|
+
attribute :name, String, example: /[:first_name:]/
|
5
|
+
attribute :email, String, example: proc { |person| "#{person.name}@example.com" }
|
6
|
+
|
7
|
+
attribute :age, Integer
|
8
|
+
|
9
|
+
attribute :full_name, FullName
|
10
|
+
attribute :aliases, Attributor::Collection.of(FullName)
|
11
|
+
|
12
|
+
attribute :address, AddressBlueprint, example: proc { |person, context| AddressBlueprint.example(context, resident: person) }
|
13
|
+
attribute :work_address, AddressBlueprint
|
14
|
+
|
15
|
+
attribute :prior_addresses, Attributor::Collection.of(AddressBlueprint)
|
16
|
+
attribute :parents do
|
17
|
+
attribute :father, String
|
18
|
+
attribute :mother, String
|
19
|
+
end
|
20
|
+
|
21
|
+
attribute :tags, Attributor::Collection.of(String)
|
22
|
+
attribute :href, String
|
23
|
+
attribute :alive, Attributor::Boolean, default: true
|
24
|
+
attribute :myself, PersonBlueprint
|
25
|
+
attribute :friends, Attributor::Collection.of(PersonBlueprint)
|
26
|
+
attribute :metadata, Attributor::Hash
|
27
|
+
end
|
28
|
+
|
29
|
+
default_fieldset do
|
30
|
+
attribute :name
|
31
|
+
attribute :full_name
|
32
|
+
attribute :address do
|
33
|
+
attribute :name
|
34
|
+
attribute :street
|
35
|
+
end
|
36
|
+
attribute :prior_addresses do
|
37
|
+
attribute :name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class AddressBlueprint < Praxis::Blueprint
|
43
|
+
attributes do
|
44
|
+
attribute :id, Integer
|
45
|
+
attribute :name, String
|
46
|
+
attribute :street, String
|
47
|
+
attribute :state, String, values: %w(OR CA)
|
48
|
+
|
49
|
+
attribute :resident, PersonBlueprint, example: proc { |address, context| PersonBlueprint.example(context, address: address) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class FullName < Attributor::Model
|
54
|
+
attributes do
|
55
|
+
attribute :first, String, example: /[:first_name:]/
|
56
|
+
attribute :last, String, example: /[:last_name:]/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class SimpleHash < Attributor::Model
|
61
|
+
attributes do
|
62
|
+
attribute :id, Integer
|
63
|
+
attribute :hash, Hash
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class SimpleHashCollection < Attributor::Model
|
68
|
+
attributes do
|
69
|
+
attribute :id, Integer
|
70
|
+
attribute :hash_collection, Attributor::Collection.of(Hash)
|
71
|
+
end
|
72
|
+
end
|
@@ -7,7 +7,7 @@ Praxis::ApiDefinition.define do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class PeopleResource
|
10
|
-
include Praxis::
|
10
|
+
include Praxis::EndpointDefinition
|
11
11
|
|
12
12
|
description 'People resource'
|
13
13
|
|
@@ -42,7 +42,7 @@ end
|
|
42
42
|
|
43
43
|
|
44
44
|
class AddressResource
|
45
|
-
include Praxis::
|
45
|
+
include Praxis::EndpointDefinition
|
46
46
|
|
47
47
|
description 'Address resource'
|
48
48
|
|
@@ -8,7 +8,7 @@ class Person < Praxis::MediaType
|
|
8
8
|
attribute :href, String, example: proc { |person| "/people/#{person.id}" }
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
default_fieldset do
|
12
12
|
attribute :id
|
13
13
|
attribute :name
|
14
14
|
end
|
@@ -20,7 +20,7 @@ class Person < Praxis::MediaType
|
|
20
20
|
attribute :size, Integer
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
default_fieldset do
|
24
24
|
attribute :href
|
25
25
|
end
|
26
26
|
|
@@ -47,7 +47,7 @@ class Address < Praxis::MediaType
|
|
47
47
|
attribute :fields, Praxis::Types::FieldSelector.for(Person)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
default_fieldset do
|
51
51
|
attribute :id
|
52
52
|
attribute :name
|
53
53
|
attribute :owner
|
@@ -95,7 +95,7 @@ class Blog < Praxis::MediaType
|
|
95
95
|
|
96
96
|
end
|
97
97
|
|
98
|
-
|
98
|
+
default_fieldset do
|
99
99
|
attribute :id
|
100
100
|
attribute :href
|
101
101
|
attribute :name
|
@@ -105,12 +105,6 @@ class Blog < Praxis::MediaType
|
|
105
105
|
|
106
106
|
attribute :owner
|
107
107
|
end
|
108
|
-
|
109
|
-
view :overview do
|
110
|
-
attribute :id
|
111
|
-
attribute :name
|
112
|
-
attribute :description
|
113
|
-
end
|
114
108
|
end
|
115
109
|
|
116
110
|
|
@@ -147,7 +141,7 @@ class Post < Praxis::MediaType
|
|
147
141
|
end
|
148
142
|
end
|
149
143
|
|
150
|
-
|
144
|
+
default_fieldset do
|
151
145
|
attribute :id
|
152
146
|
attribute :href
|
153
147
|
|
@@ -198,25 +192,11 @@ class User < Praxis::MediaType
|
|
198
192
|
example: proc { |user,ctx| Post::CollectionSummary.example(ctx, href: "#{user.href}/posts") }
|
199
193
|
end
|
200
194
|
|
201
|
-
|
195
|
+
default_fieldset do
|
202
196
|
attribute :id
|
203
197
|
attribute :href
|
204
198
|
|
205
199
|
attribute :first
|
206
200
|
attribute :last
|
207
201
|
end
|
208
|
-
|
209
|
-
view :extended do
|
210
|
-
attribute :id
|
211
|
-
attribute :href
|
212
|
-
|
213
|
-
attribute :first
|
214
|
-
attribute :last
|
215
|
-
attribute :primary_blog, view: :overview
|
216
|
-
end
|
217
|
-
|
218
|
-
view :with_post_links do
|
219
|
-
attribute :id
|
220
|
-
attribute :posts, view: :link
|
221
|
-
end
|
222
202
|
end
|
data/tasks/thor/app.rb
CHANGED
@@ -13,41 +13,15 @@ module PraxisGen
|
|
13
13
|
# Generator for a blank new app (with a full skeleton ready to get you going)
|
14
14
|
def new
|
15
15
|
puts "Creating new blank Praxis app under #{app_name}"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
private
|
25
|
-
def create_root_files
|
26
|
-
['config.ru','Gemfile','Guardfile','Rakefile','README.md'].each do |file|
|
27
|
-
copy_file file, "#{app_name}/#{file}"
|
16
|
+
# Copy example files
|
17
|
+
['config.ru','Gemfile','Rakefile','README.md'].each do |file|
|
18
|
+
copy_file file, verbose: true
|
19
|
+
end
|
20
|
+
# Copy example directories
|
21
|
+
root_dirs = ['config','app','design','spec','docs']
|
22
|
+
root_dirs.each do |dir|
|
23
|
+
directory dir, recursive: true
|
28
24
|
end
|
29
25
|
end
|
30
|
-
|
31
|
-
def create_config
|
32
|
-
copy_file "config/environment.rb", "#{app_name}/config/environment.rb"
|
33
|
-
copy_file "config/rainbows.rb", "#{app_name}/config/rainbows.rb"
|
34
|
-
end
|
35
|
-
|
36
|
-
def create_app
|
37
|
-
directory "app", "#{app_name}/app", :recursive => true
|
38
|
-
end
|
39
|
-
|
40
|
-
def create_design
|
41
|
-
directory "design", "#{app_name}/design", :recursive => true
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_spec
|
45
|
-
directory "spec", "#{app_name}/spec", :recursive => true
|
46
|
-
end
|
47
|
-
|
48
|
-
def create_docs
|
49
|
-
directory "docs", "#{app_name}/docs", :recursive => true
|
50
|
-
end
|
51
|
-
|
52
26
|
end
|
53
27
|
end
|
data/tasks/thor/example.rb
CHANGED
@@ -1,291 +1,51 @@
|
|
1
1
|
|
2
2
|
module PraxisGen
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# Returns relative path for the new application
|
49
|
-
#
|
50
|
-
# @return [String]
|
51
|
-
#
|
52
|
-
# @example
|
53
|
-
# # > /praxis generate My-test_praxisApp
|
54
|
-
# app_dir_pathname #=> 'mytest_praxisapp'
|
55
|
-
#
|
56
|
-
#
|
57
|
-
def app_dir_pathname
|
58
|
-
@app_dir_pathname ||= Pathname.new(app_name)
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
# Returns path string built from the set of the given strings
|
63
|
-
#
|
64
|
-
# @param [String,Array] strings
|
65
|
-
#
|
66
|
-
# @return [String]
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
# path('a', 'b', 'c') #=> 'my_test_app/a/b/c'
|
70
|
-
#
|
71
|
-
def path(*strings)
|
72
|
-
app_dir_pathname.join(*strings).to_s
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
# Creates './config/environment.rb' file
|
77
|
-
#
|
78
|
-
# @return [void]
|
79
|
-
#
|
80
|
-
def generate_config_environment_rb
|
81
|
-
create_file path('config/environment.rb') do
|
82
|
-
<<-RUBY
|
83
|
-
# Main entry point - DO NOT MODIFY THIS FILE
|
84
|
-
ENV['RACK_ENV'] ||= 'development'
|
85
|
-
|
86
|
-
Bundler.require(:default, ENV['RACK_ENV'])
|
87
|
-
|
88
|
-
# Default application layout.
|
89
|
-
# NOTE: This layout need NOT be specified explicitly.
|
90
|
-
# It is provided just for illustration.
|
91
|
-
Praxis::Application.instance.layout do
|
92
|
-
map :initializers, 'config/initializers/**/*'
|
93
|
-
map :lib, 'lib/**/*'
|
94
|
-
map :design, 'design/' do
|
95
|
-
map :api, 'api.rb'
|
96
|
-
map :media_types, '**/media_types/**/*'
|
97
|
-
map :resources, '**/resources/**/*'
|
98
|
-
end
|
99
|
-
map :app, 'app/' do
|
100
|
-
map :models, 'models/**/*'
|
101
|
-
map :controllers, '**/controllers/**/*'
|
102
|
-
map :responses, '**/responses/**/*'
|
103
|
-
end
|
104
|
-
end
|
105
|
-
RUBY
|
106
|
-
end
|
107
|
-
nil
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
# Creates './Gemfile' file
|
112
|
-
#
|
113
|
-
# @return [void]
|
114
|
-
#
|
115
|
-
def generate_gemfile
|
116
|
-
create_file path('Gemfile') do
|
117
|
-
<<-RUBY
|
118
|
-
source 'https://rubygems.org'
|
119
|
-
|
120
|
-
gem 'praxis'
|
121
|
-
gem 'rack', '~> 1.0'
|
122
|
-
gem 'rake'
|
123
|
-
|
124
|
-
group :development, :test do
|
125
|
-
gem 'rspec'
|
126
|
-
end
|
127
|
-
RUBY
|
128
|
-
end
|
129
|
-
nil
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
# Creates './Rakefile' file
|
134
|
-
#
|
135
|
-
# @return [void]
|
136
|
-
#
|
137
|
-
def generate_rakefile
|
138
|
-
create_file path('Rakefile') do
|
139
|
-
<<-RUBY
|
140
|
-
require 'praxis'
|
141
|
-
require 'praxis/tasks'
|
142
|
-
RUBY
|
143
|
-
end
|
144
|
-
nil
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
# Creates './config.ru' file
|
149
|
-
#
|
150
|
-
# @return [void]
|
151
|
-
#
|
152
|
-
def generate_config_ru
|
153
|
-
create_file path('config.ru') do
|
154
|
-
<<-RUBY
|
155
|
-
#\\ -p 8888
|
156
|
-
|
157
|
-
require 'bundler/setup'
|
158
|
-
require 'praxis'
|
159
|
-
|
160
|
-
application = Praxis::Application.instance
|
161
|
-
application.logger = Logger.new(STDOUT)
|
162
|
-
application.setup
|
163
|
-
|
164
|
-
run application
|
165
|
-
RUBY
|
166
|
-
end
|
3
|
+
class Example < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
namespace "praxis:example"
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
File.dirname(__FILE__) + "/templates/generator/example_app"
|
10
|
+
end
|
11
|
+
|
12
|
+
argument :app_name, required: true
|
13
|
+
desc "example", "Generates a new example application under an <app_name> directory to showcase some features"
|
14
|
+
|
15
|
+
def example
|
16
|
+
sanitized = app_name.downcase.gsub(/[^a-z0-9_\-.]/, '')
|
17
|
+
puts "APP_NAME: #{app_name}"
|
18
|
+
raise "Please use only letters, numbers, underscores, dashes or periods for the app name" unless sanitized == app_name
|
19
|
+
|
20
|
+
# Copy example files
|
21
|
+
root_files = ['Gemfile','config.ru','Rakefile']
|
22
|
+
root_files.each do |file|
|
23
|
+
copy_file file, verbose: true
|
24
|
+
end
|
25
|
+
# Copy example directories
|
26
|
+
root_dirs = ['app','config','design','db','spec']
|
27
|
+
root_dirs.each do |dir|
|
28
|
+
directory dir, recursive: true
|
29
|
+
end
|
30
|
+
|
31
|
+
puts
|
32
|
+
puts "To run the example application:"
|
33
|
+
puts
|
34
|
+
puts " cd #{app_name}"
|
35
|
+
puts " bundle"
|
36
|
+
puts " bundle exec rake db:create db:migrate db:seed # To create/migrate/seed the dev DB"
|
37
|
+
puts " bundle exec rackup # To start the web server"
|
38
|
+
puts
|
39
|
+
puts "From another terminal/app, use curl (or your favorite HTTP client) to retrieve data from the API"
|
40
|
+
puts " For example: "
|
41
|
+
puts " Get all users without filters or limit, and display only uid, and last_name fields"
|
42
|
+
puts " curl -H 'X-Api-Version: 1' http://localhost:9292/users?fields=uid,last_name"
|
43
|
+
puts
|
44
|
+
puts " Get the last 5 users, ordered by last_name (descending), and display only uid, and last_name fields"
|
45
|
+
puts " curl -H 'X-Api-Version: 1' 'http://localhost:9292/users?fields=uid,last_name&order=-last_name&pagination=by%3Dlast_name,items%3D5' "
|
46
|
+
puts " (Note: To list all routes use: bundle exec rake praxis:routes)"
|
47
|
+
puts
|
167
48
|
nil
|
168
49
|
end
|
169
|
-
|
170
|
-
|
171
|
-
def generate_app_definitions_hello_world
|
172
|
-
create_file path('design/api.rb') do
|
173
|
-
<<-RUBY
|
174
|
-
# Use this file to define your response templates and traits.
|
175
|
-
#
|
176
|
-
# For example, to define a response template:
|
177
|
-
# response_template :custom do |media_type:|
|
178
|
-
# status 200
|
179
|
-
# media_type media_type
|
180
|
-
# end
|
181
|
-
Praxis::ApiDefinition.define do
|
182
|
-
# Trait that when included will require a Bearer authorization header to be passed in.
|
183
|
-
trait :authorized do
|
184
|
-
headers do
|
185
|
-
key "Authorization", String, regexp: /^.*Bearer\s/, required: true
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
RUBY
|
190
|
-
end
|
191
|
-
|
192
|
-
create_file path('design/resources/hello.rb') do
|
193
|
-
<<-RUBY
|
194
|
-
module V1
|
195
|
-
module ApiResources
|
196
|
-
class Hello
|
197
|
-
include Praxis::ResourceDefinition
|
198
|
-
|
199
|
-
media_type V1::MediaTypes::Hello
|
200
|
-
version '1.0'
|
201
|
-
|
202
|
-
prefix '/api/hello'
|
203
|
-
|
204
|
-
# Will apply to all actions of this resource
|
205
|
-
trait :authorized
|
206
|
-
|
207
|
-
action_defaults do
|
208
|
-
response :ok
|
209
|
-
end
|
210
|
-
|
211
|
-
action :index do
|
212
|
-
|
213
|
-
routing do
|
214
|
-
get ''
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
action :show do
|
219
|
-
|
220
|
-
routing do
|
221
|
-
get '/:id'
|
222
|
-
end
|
223
|
-
params do
|
224
|
-
attribute :id, Integer, required: true, min: 0
|
225
|
-
end
|
226
|
-
response :not_found
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
RUBY
|
232
|
-
end
|
233
|
-
|
234
|
-
create_file path('design/media_types/hello.rb') do
|
235
|
-
<<-RUBY
|
236
|
-
module V1
|
237
|
-
module MediaTypes
|
238
|
-
class Hello < Praxis::MediaType
|
239
|
-
|
240
|
-
identifier 'application/json'
|
241
|
-
|
242
|
-
attributes do
|
243
|
-
attribute :string, String
|
244
|
-
end
|
245
|
-
|
246
|
-
view :default do
|
247
|
-
attribute :string
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
RUBY
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
|
257
|
-
def generate_app_controllers_hello_world
|
258
|
-
create_file path('app/controllers/hello.rb') do
|
259
|
-
<<-RUBY
|
260
|
-
module V1
|
261
|
-
class Hello
|
262
|
-
include Praxis::Controller
|
263
|
-
|
264
|
-
implements V1::ApiResources::Hello
|
265
|
-
|
266
|
-
HELLO_WORLD = [ 'Hello world!', 'Привет мир!', 'Hola mundo!', '你好世界!', 'こんにちは世界!' ]
|
267
|
-
|
268
|
-
def index(**params)
|
269
|
-
response.headers['Content-Type'] = 'application/json'
|
270
|
-
response.body = HELLO_WORLD.to_json
|
271
|
-
response
|
272
|
-
end
|
273
|
-
|
274
|
-
def show(id:, **other_params)
|
275
|
-
hello = HELLO_WORLD[id]
|
276
|
-
if hello
|
277
|
-
response.body = { id: id, data: hello }
|
278
|
-
else
|
279
|
-
self.response = Praxis::Responses::NotFound.new(body: "Hello word with index \#{id} not found in our DB")
|
280
|
-
end
|
281
|
-
response.headers['Content-Type'] = 'application/json'
|
282
|
-
response
|
283
|
-
end
|
284
50
|
end
|
285
51
|
end
|
286
|
-
RUBY
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
end
|
291
|
-
end
|