rails-formation 0.0.0.1 → 0.0.0.4
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/bin/formation +1 -1
- data/lib/rails-formation/formatters/factories/value.rb +1 -1
- data/lib/rails-formation/formatters/factory.rb +1 -1
- data/lib/rails-formation/formatters/migration.rb +11 -0
- data/lib/rails-formation/formatters/migrations/options.rb +19 -0
- data/lib/rails-formation/formatters/model.rb +7 -0
- data/lib/rails-formation/formatters/models/association.rb +37 -0
- data/lib/rails-formation/templates/factory.rb.tt +3 -0
- data/lib/rails-formation/templates/migration.rb.tt +4 -4
- data/lib/rails-formation/templates/model.rb.tt +5 -0
- data/lib/rails-formation/version.rb +1 -1
- data/lib/rails_formation.rb +8 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8efb69cf115eb4c7ca797d5992be87fa2a87eb43846b939454f9c59b42142e1c
|
4
|
+
data.tar.gz: 237ccc291969455ce85cc68e3a73b2989ccd504550b945aeb0e82930bd6773dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561247aecde1b2afc1f5aad8a26fb34da6130c97435d0f5a0b4748b86ab6f26e1952bd09af8c279ba1f0f8ea76e773dde4412beac5d5d5174300dd1cabdf9796
|
7
|
+
data.tar.gz: '038e3871279c32d1365f7cb8beaf66bcc7f0433ba04d7fb989b80597fc84148d31d443496fc73301954a7fd7e2d3c216f90872270790f38a12ee17fed5d63cc1'
|
data/bin/formation
CHANGED
@@ -49,7 +49,7 @@ module RailsFormation
|
|
49
49
|
'email' => 'FFaker::Internet.email',
|
50
50
|
'username' => 'FFaker::Internet.user_name',
|
51
51
|
'domain' => 'FFaker::Internet.domain_name',
|
52
|
-
'slug' => "
|
52
|
+
'slug' => "FFaker::Internet.slug(nil, '-')",
|
53
53
|
'job_title' => 'FFaker::Job.title',
|
54
54
|
'locale' => 'FFaker::Locale.code',
|
55
55
|
'language' => 'FFaker::Locale.language',
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'migrations/column'
|
4
4
|
require_relative 'migrations/index'
|
5
|
+
require_relative 'migrations/options'
|
5
6
|
|
6
7
|
module RailsFormation
|
7
8
|
module Formatters
|
@@ -25,10 +26,20 @@ module RailsFormation
|
|
25
26
|
migration_configuration.fetch('table')
|
26
27
|
end
|
27
28
|
|
29
|
+
def migration_name
|
30
|
+
migration_configuration.fetch('migration_name')
|
31
|
+
end
|
32
|
+
|
28
33
|
def timestamps?
|
29
34
|
migration_configuration.fetch('timestamps', false)
|
30
35
|
end
|
31
36
|
|
37
|
+
def table_options
|
38
|
+
RailsFormation::Formatters::Migrations::Options.new(
|
39
|
+
migration_configuration.fetch('options', [])
|
40
|
+
).to_s
|
41
|
+
end
|
42
|
+
|
32
43
|
def columns
|
33
44
|
migration_configuration.fetch('columns', []).map do |config|
|
34
45
|
RailsFormation::Formatters::Migrations::Column.new(config).to_s
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsFormation
|
4
|
+
module Formatters
|
5
|
+
module Migrations
|
6
|
+
class Options
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
return if @options.size.zero?
|
13
|
+
|
14
|
+
@options.map { |option| option.values.join(': ') }.join(', ')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'models/validation'
|
4
|
+
require_relative 'models/association'
|
4
5
|
|
5
6
|
module RailsFormation
|
6
7
|
module Formatters
|
@@ -24,6 +25,12 @@ module RailsFormation
|
|
24
25
|
model_configuration.fetch('name')
|
25
26
|
end
|
26
27
|
|
28
|
+
def associations
|
29
|
+
model_configuration.fetch('associations', []).map do |config|
|
30
|
+
RailsFormation::Formatters::Models::Association.new(config).to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
27
34
|
def validations
|
28
35
|
models_with_validations = model_configuration.fetch('columns', []).select do |config|
|
29
36
|
config.fetch('validations', []).size.positive?
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsFormation
|
4
|
+
module Formatters
|
5
|
+
module Models
|
6
|
+
class Association
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
base_def = "#{relation} :#{destination}"
|
13
|
+
|
14
|
+
return base_def if options.size.zero?
|
15
|
+
|
16
|
+
options_def = options.map { |option| option.values.join(': ') }.join(', ')
|
17
|
+
|
18
|
+
"#{base_def}, #{options_def}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def relation
|
24
|
+
@config.fetch('type')
|
25
|
+
end
|
26
|
+
|
27
|
+
def destination
|
28
|
+
@config.fetch('destination')
|
29
|
+
end
|
30
|
+
|
31
|
+
def options
|
32
|
+
@config.fetch('options', [])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class Create<%=
|
1
|
+
class Create<%= migration_name %> < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
|
-
create_table :<%= table_name %> do |t|
|
3
|
+
<% if table_options.nil? %>create_table :<%= table_name %> do |t|<% else %>create_table :<%= table_name %>, <%= table_options %> do |t|<% end %>
|
4
4
|
<% columns.each do |column| -%>
|
5
5
|
<%= column %>
|
6
6
|
<% end -%>
|
7
|
-
|
8
|
-
|
7
|
+
<%- if timestamps? -%>
|
8
|
+
t.timestamps
|
9
9
|
<% end -%>
|
10
10
|
end
|
11
11
|
|
data/lib/rails_formation.rb
CHANGED
@@ -34,8 +34,13 @@ module RailsFormation
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def generate_project(template)
|
37
|
-
|
38
|
-
|
37
|
+
if template['architecture'] == 'api'
|
38
|
+
system "rails _#{RailsFormation::RAILS_VERSION}_ new #{template['app_name']} --api -d=postgresql"
|
39
|
+
else
|
40
|
+
system "rails _#{RailsFormation::RAILS_VERSION}_ new #{template['app_name']} -d=postgresql"
|
41
|
+
end
|
42
|
+
|
43
|
+
Dir.chdir(template['app_name'])
|
39
44
|
end
|
40
45
|
|
41
46
|
def bundle_and_install_gems(rubygems)
|
@@ -79,7 +84,7 @@ module RailsFormation
|
|
79
84
|
|
80
85
|
def create_and_build_models(models)
|
81
86
|
models.each do |config|
|
82
|
-
model_name = "#{config.fetch('
|
87
|
+
model_name = "#{config.fetch('file_name').downcase}.rb"
|
83
88
|
model_path = File.join(Dir.pwd, 'app', 'models', model_name)
|
84
89
|
|
85
90
|
::RailsFormation::Formatters::Model.new([config, model_path]).invoke_all
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-formation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paweł Dąbrowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffaker
|
@@ -128,7 +128,9 @@ files:
|
|
128
128
|
- lib/rails-formation/formatters/migration.rb
|
129
129
|
- lib/rails-formation/formatters/migrations/column.rb
|
130
130
|
- lib/rails-formation/formatters/migrations/index.rb
|
131
|
+
- lib/rails-formation/formatters/migrations/options.rb
|
131
132
|
- lib/rails-formation/formatters/model.rb
|
133
|
+
- lib/rails-formation/formatters/models/association.rb
|
132
134
|
- lib/rails-formation/formatters/models/validation.rb
|
133
135
|
- lib/rails-formation/formatters/models/validations/base.rb
|
134
136
|
- lib/rails-formation/formatters/models/validations/comparsion.rb
|
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
- !ruby/object:Gem::Version
|
176
178
|
version: '0'
|
177
179
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.2.32
|
179
181
|
signing_key:
|
180
182
|
specification_version: 4
|
181
183
|
summary: Templates for Rails bootstraping
|