camille 0.2.0 → 0.3.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/camille/generators/install_generator.rb +23 -0
- data/lib/camille/generators/schema_generator.rb +14 -0
- data/lib/camille/generators/templates/configuration.rb +6 -0
- data/lib/camille/generators/templates/schema_example.rb +35 -0
- data/lib/camille/generators/templates/schema_template.erb +14 -0
- data/lib/camille/generators/templates/type_example.rb +10 -0
- data/lib/camille/generators/templates/type_template.erb +9 -0
- data/lib/camille/generators/type_generator.rb +14 -0
- data/lib/camille/loader.rb +41 -25
- data/lib/camille/main_controller.rb +1 -5
- data/lib/camille/railtie.rb +5 -2
- data/lib/camille/schema.rb +0 -10
- data/lib/camille/type.rb +0 -9
- data/lib/camille/version.rb +1 -1
- data/lib/camille.rb +5 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5779c76d0ca3c695e1e15d0870d94be5739449f7ad1b9422ab9944d139f3a6d1
|
4
|
+
data.tar.gz: 855906b19324060e4fb8578451e1fd77f692918f6722a81b9f3fbdc5cbf48fd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e555aebf740ecd06dcf96928a3aeafe414430a7d439a83679da90d2e60e23a97cd28bc583a473ddab76c60275e31668b76f9220ca2278c21ecceb8f2f11743fa
|
7
|
+
data.tar.gz: 00bf823aa9f394c1198cd492f42cd716b8bd59c08fe7e704df64aa92cdb927198ad87761f867de9b59153cba96490190292296755ef1642bd9c759820b00ecc0
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module Camille
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
desc 'install camille'
|
8
|
+
|
9
|
+
def copy_configuration_file
|
10
|
+
copy_file "configuration.rb", "config/camille/configuration.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_type_example
|
14
|
+
copy_file "type_example.rb", "config/camille/types/example.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_schema_example
|
18
|
+
copy_file "schema_example.rb", "config/camille/schemas/examples.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module Camille
|
3
|
+
module Generators
|
4
|
+
class SchemaGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
desc 'generate camille schema'
|
8
|
+
|
9
|
+
def generate_type_file
|
10
|
+
template 'schema_template.erb', "config/camille/schemas/#{@name}.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
using Camille::CoreExt
|
2
|
+
|
3
|
+
class Camille::Schemas::Examples < Camille::Schema
|
4
|
+
include Camille::Types
|
5
|
+
|
6
|
+
get :find do
|
7
|
+
params(
|
8
|
+
id: Number
|
9
|
+
)
|
10
|
+
|
11
|
+
response(
|
12
|
+
example?: Example
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
get :list do
|
17
|
+
response(
|
18
|
+
examples: Example[]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
post :update do
|
23
|
+
params(
|
24
|
+
id: Number,
|
25
|
+
example: Example
|
26
|
+
)
|
27
|
+
|
28
|
+
response(
|
29
|
+
success: Boolean,
|
30
|
+
errors: {
|
31
|
+
message: String
|
32
|
+
}[]
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module Camille
|
3
|
+
module Generators
|
4
|
+
class TypeGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
desc 'generate camille type'
|
8
|
+
|
9
|
+
def generate_type_file
|
10
|
+
template 'type_template.erb', "config/camille/types/#{@name}.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/camille/loader.rb
CHANGED
@@ -10,8 +10,25 @@ module Camille
|
|
10
10
|
synchronize do
|
11
11
|
loader = Zeitwerk::Loader.new
|
12
12
|
loader.enable_reloading if !app.config.cache_classes
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
types_dir = "#{app.root}/config/camille/types"
|
15
|
+
schemas_dir = "#{app.root}/config/camille/schemas"
|
16
|
+
|
17
|
+
if Dir.exist? types_dir
|
18
|
+
loader.push_dir types_dir, namespace: Camille::Types
|
19
|
+
else
|
20
|
+
unless inside_generator?
|
21
|
+
puts "[Camille Warning] Expected folder `config/camille/types`. Run `rails g camille:install` to fix it."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if Dir.exist? schemas_dir
|
26
|
+
loader.push_dir schemas_dir, namespace: Camille::Schemas
|
27
|
+
else
|
28
|
+
unless inside_generator?
|
29
|
+
puts "[Camille Warning] Expected folder `config/camille/schemas`. Run `rails g camille:install` to fix it."
|
30
|
+
end
|
31
|
+
end
|
15
32
|
|
16
33
|
loader.setup
|
17
34
|
@zeitwerk_loader = loader
|
@@ -22,17 +39,6 @@ module Camille
|
|
22
39
|
end
|
23
40
|
end
|
24
41
|
|
25
|
-
def eager_load
|
26
|
-
@eager_loading = true
|
27
|
-
load @configuration_location
|
28
|
-
@zeitwerk_loader.eager_load
|
29
|
-
@eager_loading = false
|
30
|
-
end
|
31
|
-
|
32
|
-
def eager_loading?
|
33
|
-
@eager_loading
|
34
|
-
end
|
35
|
-
|
36
42
|
def reload_types_and_schemas
|
37
43
|
synchronize do
|
38
44
|
Camille::Loader.loaded_types.clear
|
@@ -69,22 +75,32 @@ module Camille
|
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
private
|
79
|
+
def eager_load
|
80
|
+
if File.exist?(@configuration_location)
|
81
|
+
load @configuration_location
|
82
|
+
else
|
83
|
+
unless inside_generator?
|
84
|
+
puts "[Camille Warning] Expected file `config/camille/configuration.rb`. Run `rails g camille:install` to fix it."
|
85
|
+
end
|
78
86
|
end
|
87
|
+
@zeitwerk_loader.eager_load
|
79
88
|
end
|
80
|
-
end
|
81
89
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
90
|
+
def construct_controller_name_to_schema_map
|
91
|
+
synchronize do
|
92
|
+
controller_name_to_schema_map.clear
|
93
|
+
loaded_schemas.each do |schema|
|
94
|
+
controller_class_name = "#{schema.klass_name}Controller"
|
95
|
+
controller_name_to_schema_map[controller_class_name] = schema
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def inside_generator?
|
101
|
+
# https://stackoverflow.com/a/53963584
|
102
|
+
!(Rails.const_defined?(:Server) || Rails.const_defined?(:Console))
|
86
103
|
end
|
87
|
-
end
|
88
104
|
|
89
105
|
end
|
90
106
|
|
@@ -3,11 +3,7 @@ require 'action_controller'
|
|
3
3
|
module Camille
|
4
4
|
class MainController < ActionController::Base
|
5
5
|
def endpoints_ts
|
6
|
-
|
7
|
-
render plain: Camille::CodeGenerator.generate_ts
|
8
|
-
else
|
9
|
-
head 404
|
10
|
-
end
|
6
|
+
render plain: Camille::CodeGenerator.generate_ts
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
data/lib/camille/railtie.rb
CHANGED
@@ -10,14 +10,17 @@ module Camille
|
|
10
10
|
Camille::Loader.setup_zeitwerk_loader(app)
|
11
11
|
|
12
12
|
app.routes.prepend do
|
13
|
-
|
13
|
+
if Rails.env.development?
|
14
|
+
get '/camille/endpoints.ts' => 'camille/main#endpoints_ts'
|
15
|
+
end
|
16
|
+
|
14
17
|
Camille::Loader.register_routes(self)
|
15
18
|
end
|
16
19
|
|
17
20
|
dir = "#{Rails.root}/config/camille"
|
18
21
|
|
19
22
|
update_checker = ActiveSupport::FileUpdateChecker.new([], {dir => ['rb']}) do
|
20
|
-
Camille::Loader.
|
23
|
+
Camille::Loader.reload_types_and_schemas
|
21
24
|
end
|
22
25
|
|
23
26
|
app.reloaders << update_checker
|
data/lib/camille/schema.rb
CHANGED
@@ -2,20 +2,10 @@ module Camille
|
|
2
2
|
class Schema
|
3
3
|
class AlreadyDefinedError < ::ArgumentError; end
|
4
4
|
|
5
|
-
include Camille::Types
|
6
|
-
|
7
5
|
def self.endpoints
|
8
6
|
@endpoints ||= {}
|
9
7
|
end
|
10
8
|
|
11
|
-
def self.const_missing name
|
12
|
-
if Camille::Loader.eager_loading?
|
13
|
-
Camille::Types.const_get(name)
|
14
|
-
else
|
15
|
-
super
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
9
|
def self.path
|
20
10
|
"/#{ActiveSupport::Inflector.underscore klass_name}"
|
21
11
|
end
|
data/lib/camille/type.rb
CHANGED
@@ -2,7 +2,6 @@ module Camille
|
|
2
2
|
# This class represents all custom types defined by the user.
|
3
3
|
class Type < BasicType
|
4
4
|
class NotImplementedError < ::NotImplementedError; end
|
5
|
-
include Camille::Types
|
6
5
|
|
7
6
|
attr_reader :underlying
|
8
7
|
|
@@ -30,14 +29,6 @@ module Camille
|
|
30
29
|
self.class.klass_name.gsub(/::/, '_')
|
31
30
|
end
|
32
31
|
|
33
|
-
def self.const_missing name
|
34
|
-
if Camille::Loader.eager_loading?
|
35
|
-
Camille::Types.const_get(name)
|
36
|
-
else
|
37
|
-
super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
32
|
def self.inherited klass
|
42
33
|
Camille::Loader.loaded_types << klass
|
43
34
|
end
|
data/lib/camille/version.rb
CHANGED
data/lib/camille.rb
CHANGED
@@ -30,6 +30,11 @@ require_relative "camille/configuration"
|
|
30
30
|
require_relative "camille/code_generator"
|
31
31
|
require_relative "camille/main_controller"
|
32
32
|
|
33
|
+
require "rails/generators"
|
34
|
+
require_relative "camille/generators/install_generator"
|
35
|
+
require_relative "camille/generators/type_generator"
|
36
|
+
require_relative "camille/generators/schema_generator"
|
37
|
+
|
33
38
|
module Camille
|
34
39
|
class Error < StandardError; end
|
35
40
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camille
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 辻彩
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -51,6 +51,14 @@ files:
|
|
51
51
|
- lib/camille/controller_extension.rb
|
52
52
|
- lib/camille/core_ext.rb
|
53
53
|
- lib/camille/endpoint.rb
|
54
|
+
- lib/camille/generators/install_generator.rb
|
55
|
+
- lib/camille/generators/schema_generator.rb
|
56
|
+
- lib/camille/generators/templates/configuration.rb
|
57
|
+
- lib/camille/generators/templates/schema_example.rb
|
58
|
+
- lib/camille/generators/templates/schema_template.erb
|
59
|
+
- lib/camille/generators/templates/type_example.rb
|
60
|
+
- lib/camille/generators/templates/type_template.erb
|
61
|
+
- lib/camille/generators/type_generator.rb
|
54
62
|
- lib/camille/line.rb
|
55
63
|
- lib/camille/loader.rb
|
56
64
|
- lib/camille/main_controller.rb
|