rails-formation 0.0.0.6 → 0.0.0.7

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rails-formation/version.rb +1 -1
  3. data/lib/rails_formation.rb +16 -85
  4. data/rails-formation.gemspec +0 -3
  5. metadata +2 -64
  6. data/lib/rails-formation/formatters/controller.rb +0 -42
  7. data/lib/rails-formation/formatters/factories/column.rb +0 -63
  8. data/lib/rails-formation/formatters/factories/default_value.rb +0 -27
  9. data/lib/rails-formation/formatters/factories/value.rb +0 -78
  10. data/lib/rails-formation/formatters/factory.rb +0 -38
  11. data/lib/rails-formation/formatters/migration.rb +0 -56
  12. data/lib/rails-formation/formatters/migrations/column.rb +0 -33
  13. data/lib/rails-formation/formatters/migrations/index.rb +0 -30
  14. data/lib/rails-formation/formatters/migrations/options.rb +0 -19
  15. data/lib/rails-formation/formatters/model.rb +0 -49
  16. data/lib/rails-formation/formatters/models/association.rb +0 -37
  17. data/lib/rails-formation/formatters/models/validation.rb +0 -41
  18. data/lib/rails-formation/formatters/models/validations/base.rb +0 -62
  19. data/lib/rails-formation/formatters/models/validations/comparsion.rb +0 -31
  20. data/lib/rails-formation/formatters/models/validations/confirmation.rb +0 -19
  21. data/lib/rails-formation/formatters/models/validations/exclusion.rb +0 -25
  22. data/lib/rails-formation/formatters/models/validations/format.rb +0 -31
  23. data/lib/rails-formation/formatters/models/validations/inclusion.rb +0 -25
  24. data/lib/rails-formation/formatters/models/validations/length.rb +0 -58
  25. data/lib/rails-formation/formatters/models/validations/numericality.rb +0 -59
  26. data/lib/rails-formation/formatters/models/validations/presence.rb +0 -19
  27. data/lib/rails-formation/formatters/models/validations/uniqueness.rb +0 -58
  28. data/lib/rails-formation/formatters/route.rb +0 -28
  29. data/lib/rails-formation/formatters/routes/resource.rb +0 -73
  30. data/lib/rails-formation/formatters/rubygem.rb +0 -24
  31. data/lib/rails-formation/formatters/rubygems/gem.rb +0 -56
  32. data/lib/rails-formation/formatters/seed.rb +0 -30
  33. data/lib/rails-formation/formatters/seeds/row.rb +0 -19
  34. data/lib/rails-formation/templates/controller.rb.tt +0 -20
  35. data/lib/rails-formation/templates/factory.rb.tt +0 -10
  36. data/lib/rails-formation/templates/migration.rb.tt +0 -16
  37. data/lib/rails-formation/templates/model.rb.tt +0 -12
  38. data/lib/rails-formation/templates/routes.rb.tt +0 -24
  39. data/lib/rails-formation/templates/seeds.rb.tt +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9469ea562d25b27c66b6880818b7e4988d081657f6ca3239648e8b81ceaaa056
4
- data.tar.gz: 5f00c9fa7aaa1ba25292d1d02ac6bad396eaaa38c7ee4a36587678a0317b79ae
3
+ metadata.gz: 8e81589480aa07b6cb398acdf1a67041c2e6c64fd064f34ddfaadab0adb0d38e
4
+ data.tar.gz: 5a959729cecd94d4582daaec57da1c4ec64d796fc69e7bff4129b698e86b87fc
5
5
  SHA512:
6
- metadata.gz: cbd92ad8f1dc4afff5af17619048cf0e9a66788d89378f222d9e81cd096eb2893adf32dd1e558b32a80fa3972439f13039d05333e6f68135404dc6d0c4839bc8
7
- data.tar.gz: 3226617d7cc7545841a28dc84c2d7a74e6ded6133aea534a213220841d976ab0e1561ee789a74e6d242957a3c1f9ec5c0d47fc449bb304fcc25a573160ae8030
6
+ metadata.gz: 44f2a5437bcb97dd274f96b76c343e387a7b1c72600a4da96f217c1cf6f51db7d99e10d05954e2c2f15703f3fd1e405fd0330c242e3384ba7f1630493dcc0f6b
7
+ data.tar.gz: 07700bfbc719f185cd5c49c82c2b9a8adf9e3b4c8d934814c622c90d1f641de92e835c5a7ad043cf8339a5ca48e5e20b88fdc7e758a17432d1299d12040e2259
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsFormation
4
- VERSION = '0.0.0.6'
4
+ VERSION = '0.0.0.7'
5
5
  RAILS_VERSION = '7.0.2.3'
6
6
  end
@@ -1,13 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'rails-formation/formatters/migration'
5
- require 'rails-formation/formatters/rubygem'
6
- require 'rails-formation/formatters/model'
7
- require 'rails-formation/formatters/factory'
8
- require 'rails-formation/formatters/seed'
9
- require 'rails-formation/formatters/route'
10
- require 'rails-formation/formatters/controller'
3
+ require 'fileutils'
11
4
  require 'rails-formation/cli/file_adapter'
12
5
  require 'rails-formation/cli/api_adapter'
13
6
  require 'rails-formation/cli/processor'
@@ -20,13 +13,11 @@ module RailsFormation
20
13
  def apply(template)
21
14
  verify_rails_installation
22
15
  generate_project(template)
23
- bundle_and_install_gems(template.fetch('rubygems', []))
24
- create_and_run_migrations(template.fetch('migrations', []))
25
- create_factories(template.fetch('factories', []))
26
- create_and_build_models(template.fetch('models', []))
27
- insert_seeds(template.fetch('seeds', []))
28
- create_routes(template.fetch('routes', []))
29
- create_controllers(template.fetch('controllers', []))
16
+ generate_files(template.fetch('files', []))
17
+
18
+ template.fetch('commands', []).each do |project_command|
19
+ system(project_command)
20
+ end
30
21
  end
31
22
 
32
23
  private
@@ -43,77 +34,17 @@ module RailsFormation
43
34
  Dir.chdir(template['app_name'])
44
35
  end
45
36
 
46
- def bundle_and_install_gems(rubygems)
47
- return if rubygems.size.zero?
48
-
49
- gemfile_path = File.join(Dir.pwd, 'Gemfile')
50
-
51
- rubygems.each do |config|
52
- ::RailsFormation::Formatters::Rubygem.new([config, gemfile_path]).invoke_all
53
- end
54
-
55
- system 'bundle install'
56
-
57
- rubygems.each do |config|
58
- config.fetch('install_commands', []).map { |command| system(command) }
59
- end
60
- end
61
-
62
- def create_and_run_migrations(migrations)
63
- return if migrations.size.zero?
64
-
65
- migrations.each do |config|
66
- table_name = config.fetch('table')
67
- migration_name = "#{Time.now.strftime('%Y%m%d%H%M%S')}_create_#{table_name}.rb"
68
- migration_path = File.join(Dir.pwd, 'db', 'migrate', migration_name)
69
- ::RailsFormation::Formatters::Migration.new([config, migration_path]).invoke_all
70
- sleep(1)
71
- end
72
-
73
- system('./bin/rails db:create')
74
- system('./bin/rails db:migrate')
75
- end
76
-
77
- def create_factories(factories)
78
- factories.each do |config|
79
- factory_name = "#{config.fetch('name')}.rb"
80
- factory_path = File.join(Dir.pwd, 'spec', 'factories', factory_name)
81
- ::RailsFormation::Formatters::Factory.new([config, factory_path]).invoke_all
37
+ def generate_files(files)
38
+ files.each do |section|
39
+ section_name = section.keys.first
40
+ puts "\e[0;39;44m#{section_name}\e[0m"
41
+ section[section_name].each do |config|
42
+ puts " -> \e[1;32;49mCreate\e[0m #{config['file_path']}"
43
+ file_path = File.join(Dir.pwd, config['file_path'])
44
+ FileUtils.mkdir_p(File.dirname(file_path))
45
+ File.write(file_path, config['code'])
46
+ end
82
47
  end
83
48
  end
84
-
85
- def create_controllers(controllers)
86
- controllers.each do |config|
87
- controller_path = File.join(Dir.pwd, 'app', 'controllers', config['file_name'])
88
-
89
- ::RailsFormation::Formatters::Controller.new([config, controller_path]).invoke_all
90
- end
91
- end
92
-
93
- def create_and_build_models(models)
94
- models.each do |config|
95
- model_name = "#{config.fetch('file_name').downcase}.rb"
96
- model_path = File.join(Dir.pwd, 'app', 'models', model_name)
97
-
98
- ::RailsFormation::Formatters::Model.new([config, model_path]).invoke_all
99
- end
100
- end
101
-
102
- def insert_seeds(seeds)
103
- return if seeds.size.zero?
104
-
105
- seeds_path = File.join(Dir.pwd, 'db', 'seeds.rb')
106
-
107
- ::RailsFormation::Formatters::Seed.new([seeds, seeds_path]).invoke_all
108
-
109
- system('./bin/rails db:seed')
110
- end
111
-
112
- def create_routes(routes)
113
- return if routes.size.zero?
114
-
115
- routes_path = File.join(Dir.pwd, 'config', 'routes.rb')
116
- ::RailsFormation::Formatters::Route.new([routes, routes_path]).invoke_all
117
- end
118
49
  end
119
50
  end
@@ -28,9 +28,6 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.required_ruby_version = '>= 2.7.0'
30
30
 
31
- spec.add_runtime_dependency 'ffaker', '~> 2.20.0'
32
- spec.add_runtime_dependency 'thor', '~> 1.2.1'
33
-
34
31
  spec.add_development_dependency 'bundler'
35
32
  spec.add_development_dependency 'rake'
36
33
  spec.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-formation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.6
4
+ version: 0.0.0.7
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-05-07 00:00:00.000000000 Z
11
+ date: 2022-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: ffaker
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 2.20.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 2.20.0
27
- - !ruby/object:Gem::Dependency
28
- name: thor
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.2.1
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.2.1
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: bundler
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -121,40 +93,6 @@ files:
121
93
  - lib/rails-formation/cli/api_adapter.rb
122
94
  - lib/rails-formation/cli/file_adapter.rb
123
95
  - lib/rails-formation/cli/processor.rb
124
- - lib/rails-formation/formatters/controller.rb
125
- - lib/rails-formation/formatters/factories/column.rb
126
- - lib/rails-formation/formatters/factories/default_value.rb
127
- - lib/rails-formation/formatters/factories/value.rb
128
- - lib/rails-formation/formatters/factory.rb
129
- - lib/rails-formation/formatters/migration.rb
130
- - lib/rails-formation/formatters/migrations/column.rb
131
- - lib/rails-formation/formatters/migrations/index.rb
132
- - lib/rails-formation/formatters/migrations/options.rb
133
- - lib/rails-formation/formatters/model.rb
134
- - lib/rails-formation/formatters/models/association.rb
135
- - lib/rails-formation/formatters/models/validation.rb
136
- - lib/rails-formation/formatters/models/validations/base.rb
137
- - lib/rails-formation/formatters/models/validations/comparsion.rb
138
- - lib/rails-formation/formatters/models/validations/confirmation.rb
139
- - lib/rails-formation/formatters/models/validations/exclusion.rb
140
- - lib/rails-formation/formatters/models/validations/format.rb
141
- - lib/rails-formation/formatters/models/validations/inclusion.rb
142
- - lib/rails-formation/formatters/models/validations/length.rb
143
- - lib/rails-formation/formatters/models/validations/numericality.rb
144
- - lib/rails-formation/formatters/models/validations/presence.rb
145
- - lib/rails-formation/formatters/models/validations/uniqueness.rb
146
- - lib/rails-formation/formatters/route.rb
147
- - lib/rails-formation/formatters/routes/resource.rb
148
- - lib/rails-formation/formatters/rubygem.rb
149
- - lib/rails-formation/formatters/rubygems/gem.rb
150
- - lib/rails-formation/formatters/seed.rb
151
- - lib/rails-formation/formatters/seeds/row.rb
152
- - lib/rails-formation/templates/controller.rb.tt
153
- - lib/rails-formation/templates/factory.rb.tt
154
- - lib/rails-formation/templates/migration.rb.tt
155
- - lib/rails-formation/templates/model.rb.tt
156
- - lib/rails-formation/templates/routes.rb.tt
157
- - lib/rails-formation/templates/seeds.rb.tt
158
96
  - lib/rails-formation/version.rb
159
97
  - lib/rails_formation.rb
160
98
  - rails-formation.gemspec
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- class Controller < Thor::Group
6
- include Thor::Actions
7
-
8
- argument :controller_configuration
9
- argument :controller_path
10
-
11
- def create_controller
12
- template('../templates/controller.rb.tt', controller_path)
13
- end
14
-
15
- def self.source_root
16
- __dir__
17
- end
18
-
19
- private
20
-
21
- def controller_class
22
- controller_configuration.fetch('class_name')
23
- end
24
-
25
- def public_actions
26
- controller_configuration.fetch('actions').select(&method(:public_action?)).map { |action| action['action'] }
27
- end
28
-
29
- def private_actions
30
- controller_configuration.fetch('actions').select(&method(:private_action?)).map { |action| action['action'] }
31
- end
32
-
33
- def public_action?(action)
34
- action['access'] == 'public'
35
- end
36
-
37
- def private_action?(action)
38
- action['access'] == 'private'
39
- end
40
- end
41
- end
42
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'default_value'
4
- require_relative 'value'
5
-
6
- module RailsFormation
7
- module Formatters
8
- module Factories
9
- class Column
10
- def initialize(config)
11
- @config = config
12
- end
13
-
14
- def to_s
15
- if @config.key?('has_confirmation')
16
- base_part = "#{name} { #{value} }"
17
- "#{base_part}\n #{name}_confirmation { #{name} }"
18
- else
19
- "#{name} { #{value} }"
20
- end
21
- end
22
-
23
- private
24
-
25
- def name
26
- @config.fetch('name')
27
- end
28
-
29
- def sql_type
30
- @config.fetch('sql_type')
31
- end
32
-
33
- def specialized
34
- @config.fetch('specialized')
35
- end
36
-
37
- def use_sql_type?
38
- specialized == 'default'
39
- end
40
-
41
- def default_value
42
- ::RailsFormation::Formatters::Factories::DefaultValue
43
- end
44
-
45
- def value
46
- if @config.key?('in')
47
- "#{@config.fetch('in')}.sample"
48
- else
49
- raw_value
50
- end
51
- end
52
-
53
- def raw_value
54
- if use_sql_type?
55
- ::RailsFormation::Formatters::Factories::DefaultValue.detect(sql_type)
56
- else
57
- ::RailsFormation::Formatters::Factories::Value.detect(specialized)
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Factories
6
- class DefaultValue
7
- MAPPINGS = {
8
- 'string' => 'FFaker::Lorem.sentence',
9
- 'text' => 'FFaker::Lorem.sentence(50)',
10
- 'boolean' => 'FFaker::Boolean.maybe',
11
- 'time' => 'Time.zone.now',
12
- 'date' => 'FFaker::Time.date',
13
- 'float' => 'FFaker::Number.decimal',
14
- 'decimal' => 'FFaker::Number.decimal',
15
- 'integer' => 'FFaker::Number.number',
16
- 'binary' => '',
17
- 'timestamp' => 'Time.now.getutc',
18
- 'datetime' => 'DateTime.now'
19
- }.freeze
20
-
21
- def self.detect(sql_type)
22
- MAPPINGS[sql_type]
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Factories
6
- class Value
7
- MAPPINGS = {
8
- 'first_name' => 'FFaker::Name.first_name',
9
- 'last_name' => 'FFaker::Name.last_name',
10
- 'zip_code' => 'FFaker::AddressUS.zip_code',
11
- 'state' => 'FFaker::AddressUS.state',
12
- 'city' => 'FFaker::Address.city',
13
- 'street_name' => 'FFaker::Address.street_name',
14
- 'building_number' => 'FFaker::Address.building_number',
15
- 'country_code' => 'FFaker::Address.country_code',
16
- 'country' => 'FFaker::Address.country',
17
- 'time_zone' => 'FFaker::Address.time_zone',
18
- 'plane_name' => 'FFaker::Airline.name',
19
- 'flight_number' => 'FFaker::Airline.flight_number',
20
- 'animal' => 'FFaker::AnimalUS.common_name',
21
- 'iban' => 'FFaker::Bank.iban',
22
- 'card_number' => 'FFaker::Bank.card_number',
23
- 'card_type' => 'FFaker::Bank.card_number',
24
- 'card_expiry_date' => 'FFaker::Bank.card_expiry_date',
25
- 'book_title' => 'FFaker::Book.title',
26
- 'book_genre' => 'FFaker::Book.genre',
27
- 'book_author' => 'FFaker::Book.author',
28
- 'book_isbn' => 'FFaker::Book.isbn',
29
- 'boolean' => 'FFaker::Boolean.maybe',
30
- 'color' => 'FFaker::Color.name',
31
- 'color_hex_code' => 'FFaker::Color.hex_code',
32
- 'company_name' => 'FFaker::Company.name',
33
- 'position' => 'FFaker::Company.position',
34
- 'currency_code' => 'FFaker::Currency.code',
35
- 'currency_name' => 'FFaker::Currency.name',
36
- 'currency_symbol' => 'FFaker::Currency.symbol',
37
- 'education_degree' => 'FFaker::Education.degree',
38
- 'school_name' => 'FFaker::Education.school_name',
39
- 'ingredient' => 'FFaker::Food.ingredient',
40
- 'vegetable' => 'FFaker::Food.vegetable',
41
- 'fruit' => 'FFaker::Food.fruit',
42
- 'meat' => 'FFaker::Food.meat',
43
- 'game_title' => 'FFaker::Game.title',
44
- 'game_category' => 'FFaker::Game.category',
45
- 'gender_binary' => 'FFaker::Gender.binary',
46
- 'gender_random' => 'FFaker::Gender.random',
47
- 'latitude' => 'FFaker::Geolocation.lat',
48
- 'longitude' => 'FFaker::Geolocation.lng',
49
- 'email' => 'FFaker::Internet.email',
50
- 'username' => 'FFaker::Internet.user_name',
51
- 'domain' => 'FFaker::Internet.domain_name',
52
- 'slug' => "FFaker::Internet.slug(nil, '-')",
53
- 'job_title' => 'FFaker::Job.title',
54
- 'locale' => 'FFaker::Locale.code',
55
- 'language' => 'FFaker::Locale.language',
56
- 'movie' => 'FFaker::Movie.title',
57
- 'name' => 'FFaker::Name.name',
58
- 'number' => 'FFaker::Number.number',
59
- 'decimal' => 'FFaker::Number.decimal',
60
- 'phone_number' => 'FFaker::PhoneNumber.phone_number',
61
- 'brand_name' => 'FFaker::Product.brand',
62
- 'product_name' => 'FFaker::Product.product_name',
63
- 'tech_skill' => 'FFaker::Skill.tech_skill',
64
- 'specialty' => 'FFaker::Skill.specialty',
65
- 'sport_name' => 'FFaker::SportUS.name',
66
- 'ssn' => 'FFaker::SSN.ssn',
67
- 'month' => 'FFaker::Time.month',
68
- 'datetime' => 'FFaker::Time.datetime',
69
- 'date' => 'FFaker::Time.date'
70
- }.freeze
71
-
72
- def self.detect(specialized)
73
- MAPPINGS[specialized]
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'factories/column'
4
-
5
- module RailsFormation
6
- module Formatters
7
- class Factory < Thor::Group
8
- include Thor::Actions
9
-
10
- argument :factory_configuration
11
- argument :factory_path
12
-
13
- def create_factory
14
- template('../templates/factory.rb.tt', factory_path)
15
- end
16
-
17
- def self.source_root
18
- __dir__
19
- end
20
-
21
- private
22
-
23
- def factory_name
24
- factory_configuration.fetch('name')
25
- end
26
-
27
- def associations
28
- factory_configuration.fetch('associations', [])
29
- end
30
-
31
- def columns
32
- factory_configuration.fetch('fields', []).map do |config|
33
- RailsFormation::Formatters::Factories::Column.new(config).to_s
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'migrations/column'
4
- require_relative 'migrations/index'
5
- require_relative 'migrations/options'
6
-
7
- module RailsFormation
8
- module Formatters
9
- class Migration < Thor::Group
10
- include Thor::Actions
11
-
12
- argument :migration_configuration
13
- argument :migration_path
14
-
15
- def create_migration
16
- template('../templates/migration.rb.tt', migration_path)
17
- end
18
-
19
- def self.source_root
20
- __dir__
21
- end
22
-
23
- private
24
-
25
- def table_name
26
- migration_configuration.fetch('table')
27
- end
28
-
29
- def migration_name
30
- migration_configuration.fetch('migration_name')
31
- end
32
-
33
- def timestamps?
34
- migration_configuration.fetch('timestamps', false)
35
- end
36
-
37
- def table_options
38
- RailsFormation::Formatters::Migrations::Options.new(
39
- migration_configuration.fetch('options', [])
40
- ).to_s
41
- end
42
-
43
- def columns
44
- migration_configuration.fetch('columns', []).map do |config|
45
- RailsFormation::Formatters::Migrations::Column.new(config).to_s
46
- end
47
- end
48
-
49
- def indices
50
- migration_configuration.fetch('indices', []).map do |config|
51
- RailsFormation::Formatters::Migrations::Index.new(table_name, config).to_s
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Migrations
6
- class Column
7
- def initialize(config)
8
- @config = config
9
- end
10
-
11
- def to_s
12
- base_definition = [
13
- 't.',
14
- @config.fetch('type'),
15
- ' :',
16
- @config.fetch('name')
17
- ].join
18
-
19
- return base_definition if @config['options'].nil? || @config['options'].size.zero?
20
-
21
- options = @config['options'].map do |option|
22
- value = option['value']
23
- parsed_value = value.is_a?(String) ? "'#{value}'" : value
24
-
25
- "#{option['name']}: #{parsed_value}"
26
- end.join(', ')
27
-
28
- [base_definition, ', ', options].join
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Migrations
6
- class Index
7
- def initialize(table_name, config)
8
- @table_name = table_name
9
- @config = config
10
- end
11
-
12
- def to_s
13
- column_slug = if @config.fetch('column_names').size == 1
14
- ":#{@config.fetch('column_names').first}"
15
- else
16
- "[#{@config.fetch('column_names').map { |col| ":#{col}" }.join(', ')}]"
17
- end
18
-
19
- base_definition = "add_index :#{@table_name}, #{column_slug}"
20
-
21
- return base_definition if @config.fetch('options', []).size.zero?
22
-
23
- options = @config['options'].map { |option| option.values.join(': ') }.join(', ')
24
-
25
- "#{base_definition}, #{options}"
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,19 +0,0 @@
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,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'models/validation'
4
- require_relative 'models/association'
5
-
6
- module RailsFormation
7
- module Formatters
8
- class Model < Thor::Group
9
- include Thor::Actions
10
-
11
- argument :model_configuration
12
- argument :model_path
13
-
14
- def create_model
15
- template('../templates/model.rb.tt', model_path)
16
- end
17
-
18
- def self.source_root
19
- __dir__
20
- end
21
-
22
- private
23
-
24
- def class_name
25
- model_configuration.fetch('name')
26
- end
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
-
34
- def validations
35
- models_with_validations = model_configuration.fetch('columns', []).select do |config|
36
- config.fetch('validations', []).size.positive?
37
- end
38
-
39
- models_with_validations.map do |config|
40
- config.fetch('validations', []).map do |val_config|
41
- ::RailsFormation::Formatters::Models::Validation.new(
42
- val_config.merge('column' => config.fetch('name'))
43
- ).to_s
44
- end
45
- end.flatten
46
- end
47
- end
48
- end
49
- end