rails-formation 0.0.0.2 → 0.0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90c130dd715c8361052ce5f50622be6d833734e68aaf4665e109a96dc9de540c
4
- data.tar.gz: 4bc386f993259e1d4707567d0d775e37343b289e6e67f479116d11a966e26854
3
+ metadata.gz: 50040a27201ad285113ca45ba39a904f4cc29e6876d6054a12253bc2294e209b
4
+ data.tar.gz: c10d8b45c7478f6592c5437346ce70682dec3463911f5f9db322822b0b812d53
5
5
  SHA512:
6
- metadata.gz: 39f9f90e9c7385f499719617f988d0dc7b8c8ff4a8bf77c9188b8cac2ae30aa6f51faacf94b2a52fa4ffc347544e1021ab3426c17375a0a407db72bc9864bd9f
7
- data.tar.gz: 431f25e9eeb72da4b3eb3d61d5241c8d7f2323a0cc857abb332714ffedfbb443cc107898cc11ba0c724c9ce95a8aa2f42a40ecc6f1a4cd9c80f066324047b1ab
6
+ metadata.gz: 7daf43d31ef3128f8e4a154d7fb76c1eee8158146b63908bfbe01346057a961dbbd23af918df1c87db4874b3f04546dbf471fa565800db32405bed4679b64362
7
+ data.tar.gz: 77415da7829c9badc09107668c5085d270a775d3c16dddfb1b362334119783d8f146b3eb3649187a31ade1b3271db3d9d4f93a91e0741569e26f05b19b7634c6
@@ -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
@@ -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.2'
4
+ VERSION = '0.0.0.3'
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)
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.2
4
+ version: 0.0.0.3
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-10 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffaker
@@ -129,6 +129,7 @@ files:
129
129
  - lib/rails-formation/formatters/migrations/column.rb
130
130
  - lib/rails-formation/formatters/migrations/index.rb
131
131
  - lib/rails-formation/formatters/model.rb
132
+ - lib/rails-formation/formatters/models/association.rb
132
133
  - lib/rails-formation/formatters/models/validation.rb
133
134
  - lib/rails-formation/formatters/models/validations/base.rb
134
135
  - lib/rails-formation/formatters/models/validations/comparsion.rb
@@ -175,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  - !ruby/object:Gem::Version
176
177
  version: '0'
177
178
  requirements: []
178
- rubygems_version: 3.1.2
179
+ rubygems_version: 3.2.32
179
180
  signing_key:
180
181
  specification_version: 4
181
182
  summary: Templates for Rails bootstraping