rails-formation 0.0.0.1 → 0.0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad157ec88ba25d8f9197ed69ad68c6a83ea79a92a38ca158c74582988b4af285
4
- data.tar.gz: dcf51b0e646da2778ca9e813b8a550881af5a08e81cdb8de3e376a1655f68bed
3
+ metadata.gz: 8efb69cf115eb4c7ca797d5992be87fa2a87eb43846b939454f9c59b42142e1c
4
+ data.tar.gz: 237ccc291969455ce85cc68e3a73b2989ccd504550b945aeb0e82930bd6773dd
5
5
  SHA512:
6
- metadata.gz: b3ffc89976c3718500ffaa12e5d96238af9dc090037fc80d648992d4705e55b058212caf86fce0afedb09fce4e70bf6ec7beb5770b1b7492ef971b046195a506
7
- data.tar.gz: 14701d72714814a0041443f315ee8c06d857a8cbd3175bddc47b18f187d71c5d8daa4a305b2aebe10c55ecd842f8b291a1ff3bb1c0797300278d9f6e688aabc3
6
+ metadata.gz: 561247aecde1b2afc1f5aad8a26fb34da6130c97435d0f5a0b4748b86ab6f26e1952bd09af8c279ba1f0f8ea76e773dde4412beac5d5d5174300dd1cabdf9796
7
+ data.tar.gz: '038e3871279c32d1365f7cb8beaf66bcc7f0433ba04d7fb989b80597fc84148d31d443496fc73301954a7fd7e2d3c216f90872270790f38a12ee17fed5d63cc1'
data/bin/formation CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'rails-formation'
4
+ require 'rails_formation'
5
5
 
6
6
  command_line_arguments = ARGV.dup
7
7
 
@@ -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' => "Faker::Internet.slug(nil, '-')",
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',
@@ -25,7 +25,7 @@ module RailsFormation
25
25
  end
26
26
 
27
27
  def associations
28
- []
28
+ factory_configuration.fetch('associations', [])
29
29
  end
30
30
 
31
31
  def columns
@@ -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
@@ -2,6 +2,9 @@ FactoryBot.define do
2
2
  factory :<%= factory_name %> do
3
3
  <% columns.each do |column| -%>
4
4
  <%= column %>
5
+ <% end -%>
6
+ <% associations.each do |association| -%>
7
+ <%= association %>
5
8
  <% end -%>
6
9
  end
7
10
  end
@@ -1,11 +1,11 @@
1
- class Create<%= table_name.capitalize %> < ActiveRecord::Migration[7.0]
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
- <% if timestamps? -%>
8
- t.timestamps
7
+ <%- if timestamps? -%>
8
+ t.timestamps
9
9
  <% end -%>
10
10
  end
11
11
 
@@ -4,4 +4,9 @@ class <%= class_name %> < ApplicationRecord
4
4
  <%= validation %>
5
5
  <% end -%>
6
6
  <% end -%>
7
+ <% if associations.any? -%>
8
+ <% associations.each do |association| -%>
9
+ <%= association %>
10
+ <% end -%>
11
+ <% end -%>
7
12
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsFormation
4
- VERSION = '0.0.0.1'
4
+ VERSION = '0.0.0.4'
5
5
  RAILS_VERSION = '7.0.2.3'
6
6
  end
@@ -34,8 +34,13 @@ module RailsFormation
34
34
  end
35
35
 
36
36
  def generate_project(template)
37
- system "rails _#{RailsFormation::RAILS_VERSION}_ new #{template['name']} -d=postgresql"
38
- Dir.chdir(template['name'])
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('name').downcase}.rb"
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.1
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-09 00:00:00.000000000 Z
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.1.2
180
+ rubygems_version: 3.2.32
179
181
  signing_key:
180
182
  specification_version: 4
181
183
  summary: Templates for Rails bootstraping