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
@@ -1,37 +0,0 @@
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,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'validations/base'
4
- require_relative 'validations/presence'
5
- require_relative 'validations/uniqueness'
6
- require_relative 'validations/length'
7
- require_relative 'validations/inclusion'
8
- require_relative 'validations/exclusion'
9
- require_relative 'validations/confirmation'
10
- require_relative 'validations/format'
11
- require_relative 'validations/numericality'
12
- require_relative 'validations/comparsion'
13
-
14
- module RailsFormation
15
- module Formatters
16
- module Models
17
- class Validation
18
- MAPPINGS = {
19
- 'presence' => ::RailsFormation::Formatters::Models::Validations::Presence,
20
- 'uniqueness' => ::RailsFormation::Formatters::Models::Validations::Uniqueness,
21
- 'length' => ::RailsFormation::Formatters::Models::Validations::Length,
22
- 'inclusion' => ::RailsFormation::Formatters::Models::Validations::Inclusion,
23
- 'exclusion' => ::RailsFormation::Formatters::Models::Validations::Exclusion,
24
- 'confirmation' => ::RailsFormation::Formatters::Models::Validations::Confirmation,
25
- 'format' => ::RailsFormation::Formatters::Models::Validations::Format,
26
- 'numericality' => ::RailsFormation::Formatters::Models::Validations::Numericality,
27
- 'comparsion' => ::RailsFormation::Formatters::Models::Validations::Comparsion
28
- }.freeze
29
-
30
- def initialize(config)
31
- @config = config
32
- end
33
-
34
- def to_s
35
- klass = MAPPINGS[@config.fetch('name')]
36
- klass.new(@config).to_s
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Base
8
- def initialize(config)
9
- @config = config
10
- end
11
-
12
- private
13
-
14
- def allow_blank_option
15
- return unless @config.fetch('allow_blank')
16
-
17
- 'allow_blank: true'
18
- end
19
-
20
- def allow_nil_option
21
- return unless @config.fetch('allow_nil')
22
-
23
- 'allow_nil: true'
24
- end
25
-
26
- def message_option
27
- return if @config.fetch('message').nil? || @config.fetch('message').empty?
28
-
29
- "message: '#{@config.fetch('message')}'"
30
- end
31
-
32
- def on_option
33
- return if @config.fetch('on_create') && @config.fetch('on_update')
34
-
35
- if @config.fetch('on_create')
36
- 'on: :create'
37
- elsif @config.fetch('on_update')
38
- 'on: :update'
39
- end
40
- end
41
-
42
- def column_name
43
- @config.fetch('column')
44
- end
45
-
46
- def base_options
47
- [
48
- allow_blank_option,
49
- allow_nil_option,
50
- message_option,
51
- on_option
52
- ].compact
53
- end
54
-
55
- def validation_options
56
- @config.fetch('options', {})
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Comparsion < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- "validates :#{column_name}, comparsion: { #{extra_options.join(', ')} }"
10
- end
11
-
12
- private
13
-
14
- def extra_options
15
- base_options | extra_validation_options
16
- end
17
-
18
- def extra_validation_options
19
- value = if validation_options['comparsion_value_type'] == 'column_value'
20
- ":#{validation_options['comparsion_value']}"
21
- else
22
- validation_options['comparsion_value']
23
- end
24
-
25
- ["#{validation_options['comparsion_operator']}: #{value}"]
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Confirmation < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- if base_options.any?
10
- "validates :#{column_name}, confirmation: { #{base_options.join(', ')} }"
11
- else
12
- "validates :#{column_name}, confirmation: true"
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Exclusion < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- "validates :#{column_name}, exclusion: { #{extra_options.join(', ')} }"
10
- end
11
-
12
- private
13
-
14
- def extra_options
15
- base_options | extra_validation_options
16
- end
17
-
18
- def extra_validation_options
19
- ["in: #{validation_options['in']}"]
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Format < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- "validates :#{column_name}, format: { #{extra_options.join(', ')} }"
10
- end
11
-
12
- private
13
-
14
- def extra_options
15
- base_options | extra_validation_options
16
- end
17
-
18
- def extra_validation_options
19
- options = []
20
-
21
- options << "with: #{validation_options['format_value']}" if validation_options['format_matcher'] == 'with'
22
-
23
- options << "without: #{validation_options['format_value']}" if validation_options['format_matcher'] == 'without'
24
-
25
- options
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Inclusion < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- "validates :#{column_name}, inclusion: { #{extra_options.join(', ')} }"
10
- end
11
-
12
- private
13
-
14
- def extra_options
15
- base_options | extra_validation_options
16
- end
17
-
18
- def extra_validation_options
19
- ["in: #{validation_options['in']}"]
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Length < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- "validates :#{column_name}, length: { #{extra_options.join(', ')} }"
10
- end
11
-
12
- private
13
-
14
- def extra_options
15
- base_options | extra_validation_options
16
- end
17
-
18
- def extra_validation_options
19
- options = []
20
-
21
- options << "is: #{validation_options['length_value']}" if exact_length?
22
-
23
- options << "minimum: #{validation_options['length_min_value']}" if min_length?
24
-
25
- options << "maximum: #{validation_options['length_max_value']}" if max_length?
26
-
27
- options << "in: #{validation_options['length_min_value']}..#{validation_options['length_max_value']}" if range_length?
28
-
29
- options
30
- end
31
-
32
- def exact_length?
33
- validation_options['length_operator_type'] == 'value' &&
34
- !validation_options['length_value'].nil?
35
- end
36
-
37
- def min_length?
38
- validation_options['length_operator_type'] == 'range' &&
39
- validation_options['length_max_value'].to_i.zero? &&
40
- validation_options['length_min_value'].to_i.positive?
41
- end
42
-
43
- def max_length?
44
- validation_options['length_operator_type'] == 'range' &&
45
- validation_options['length_min_value'].to_i.zero? &&
46
- validation_options['length_max_value'].to_i.positive?
47
- end
48
-
49
- def range_length?
50
- validation_options['length_operator_type'] == 'range' &&
51
- validation_options['length_min_value'].to_i.positive? &&
52
- validation_options['length_max_value'].to_i.positive?
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Numericality < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- "validates :#{column_name}, numericality: { #{extra_options.join(', ')} }"
10
- end
11
-
12
- private
13
-
14
- def extra_options
15
- base_options | extra_validation_options
16
- end
17
-
18
- def extra_validation_options
19
- options = []
20
-
21
- if validation_options['numericality_operator'] == 'greater_than'
22
- options << "greater_than: #{validation_options['numericality_value']}"
23
- end
24
-
25
- options << 'only_integer: true' if validation_options['numericality_operator'] == 'only_integer'
26
-
27
- if validation_options['numericality_operator'] == 'greater_than_or_equal_to'
28
- options << "greater_than_or_equal_to: #{validation_options['numericality_value']}"
29
- end
30
-
31
- if validation_options['numericality_operator'] == 'equal_to'
32
- options << "equal_to: #{validation_options['numericality_value']}"
33
- end
34
-
35
- if validation_options['numericality_operator'] == 'less_than'
36
- options << "less_than: #{validation_options['numericality_value']}"
37
- end
38
-
39
- if validation_options['numericality_operator'] == 'less_than_or_equal_to'
40
- options << "less_than_or_equal_to: #{validation_options['numericality_value']}"
41
- end
42
-
43
- if validation_options['numericality_operator'] == 'other_than'
44
- options << "other_than: #{validation_options['numericality_value']}"
45
- end
46
-
47
- options << "in: #{validation_options['numericality_value']}" if validation_options['numericality_operator'] == 'in'
48
-
49
- options << 'odd: true' if validation_options['numericality_operator'] == 'odd'
50
-
51
- options << 'even: true' if validation_options['numericality_operator'] == 'even'
52
-
53
- options
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Presence < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- if base_options.any?
10
- "validates :#{column_name}, presence: { #{base_options.join(', ')} }"
11
- else
12
- "validates :#{column_name}, presence: true"
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Models
6
- module Validations
7
- class Uniqueness < RailsFormation::Formatters::Models::Validations::Base
8
- def to_s
9
- if extra_options.any?
10
- "validates :#{column_name}, uniqueness: { #{extra_options.join(', ')} }"
11
- else
12
- "validates :#{column_name}, uniqueness: true"
13
- end
14
- end
15
-
16
- private
17
-
18
- def extra_options
19
- base_options | extra_validation_options
20
- end
21
-
22
- def extra_validation_options
23
- options = []
24
-
25
- options << 'case_sensitive: false' unless case_sensitive?
26
-
27
- options << scope unless blank_scope?
28
-
29
- options
30
- end
31
-
32
- def case_sensitive?
33
- validation_options['uniqueness_case_sensitive'].to_i == 1
34
- end
35
-
36
- def blank_scope?
37
- validation_options['uniqueness_scope'].nil? ||
38
- validation_options['uniqueness_scope'].reject(&:empty?).size.zero?
39
- end
40
-
41
- def scope
42
- return [] if validation_options['uniqueness_scope'].nil?
43
-
44
- sanitized_scope = validation_options['uniqueness_scope'].reject(&:empty?)
45
-
46
- return [] if sanitized_scope.size.zero?
47
-
48
- if sanitized_scope.size == 1
49
- "scope: :#{sanitized_scope.first}"
50
- else
51
- "scope: [#{sanitized_scope.map { |s| ":#{s}" }.join(', ')}]"
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'routes/resource'
4
-
5
- module RailsFormation
6
- module Formatters
7
- class Route < Thor::Group
8
- include Thor::Actions
9
-
10
- argument :routes_configuration
11
- argument :routes_path
12
-
13
- def insert_routes
14
- template('../templates/routes.rb.tt', routes_path)
15
- end
16
-
17
- def self.source_root
18
- __dir__
19
- end
20
-
21
- private
22
-
23
- def resources
24
- routes_configuration.map { |config| ::RailsFormation::Formatters::Routes::Resource.new(config) }
25
- end
26
- end
27
- end
28
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Routes
6
- class Resource
7
- def initialize(config)
8
- @config = config
9
- end
10
-
11
- def start_line
12
- if actions_line.nil?
13
- "resources :#{resource_name}"
14
- else
15
- "resources :#{resource_name}, #{actions_line}"
16
- end
17
- end
18
-
19
- def additional_routes
20
- mappings = {}
21
-
22
- mappings['member'] = member_routes.map(&method(:build_route)) if member_routes.size.positive?
23
-
24
- mappings['collection'] = collection_routes.map(&method(:build_route)) if collection_routes.size.positive?
25
-
26
- mappings
27
- end
28
-
29
- def create_block?
30
- member_routes.size.positive? || collection_routes.size.positive?
31
- end
32
-
33
- private
34
-
35
- def build_route(route)
36
- "#{route['request']} :#{route['action']}"
37
- end
38
-
39
- def actions_line
40
- return if actions.size == default_actions.size
41
-
42
- if actions.size > 3
43
- except_actions = (default_actions - actions).map { |action| ":#{action}" }
44
- "except: [#{except_actions.join(', ')}]"
45
- else
46
- only_actions = actions.map { |action| ":#{action}" }
47
- "only: [#{only_actions.join(', ')}]"
48
- end
49
- end
50
-
51
- def resource_name
52
- @config.fetch('resource')
53
- end
54
-
55
- def actions
56
- @config.fetch('restful_actions')
57
- end
58
-
59
- def default_actions
60
- %w[index show new create edit update destroy]
61
- end
62
-
63
- def member_routes
64
- @config.fetch('additional_routes').fetch('member', [])
65
- end
66
-
67
- def collection_routes
68
- @config.fetch('additional_routes').fetch('collection', [])
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'rubygems/gem'
4
-
5
- module RailsFormation
6
- module Formatters
7
- class Rubygem < Thor::Group
8
- include Thor::Actions
9
-
10
- argument :gem
11
- argument :gemfile_path
12
-
13
- def apply_to_gemfile
14
- gem_definition = ::RailsFormation::Formatters::Rubygems::Gem.new(gem, gemfile_path)
15
-
16
- insert_into_file gemfile_path, gem_definition.to_s, gem_definition.options
17
- end
18
-
19
- def self.source_root
20
- __dir__
21
- end
22
- end
23
- end
24
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsFormation
4
- module Formatters
5
- module Rubygems
6
- class Gem
7
- def initialize(config, gemfile_path)
8
- @config = config
9
- @gemfile_path = gemfile_path
10
- end
11
-
12
- def to_s
13
- if create_group?
14
- "#{groups_def} #{base_definition}end"
15
- elsif insert_after?
16
- " #{base_definition}"
17
- else
18
- base_definition
19
- end
20
- end
21
-
22
- def insert_after?
23
- !groups_def.nil?
24
- end
25
-
26
- def options
27
- if !create_group? && insert_after?
28
- { after: groups_def }
29
- else
30
- {}
31
- end
32
- end
33
-
34
- private
35
-
36
- def base_definition
37
- "gem '#{@config['name']}', '#{@config['version']}'\n"
38
- end
39
-
40
- def create_group?
41
- return false if groups_def.nil?
42
-
43
- !File.read(@gemfile_path).include?(groups_def.gsub("\n", ''))
44
- end
45
-
46
- def groups_def
47
- return if @config.fetch('groups', []).size.zero?
48
-
49
- groups_def = @config['groups'].map { |name| ":#{name}" }.join(', ')
50
-
51
- "group #{groups_def} do\n"
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'seeds/row'
4
-
5
- module RailsFormation
6
- module Formatters
7
- class Seed < Thor::Group
8
- include Thor::Actions
9
-
10
- argument :seeds_configuration
11
- argument :seeds_path
12
-
13
- def update_seeds
14
- template('../templates/seeds.rb.tt', seeds_path)
15
- end
16
-
17
- def self.source_root
18
- __dir__
19
- end
20
-
21
- private
22
-
23
- def seeds
24
- seeds_configuration.map do |config|
25
- RailsFormation::Formatters::Seeds::Row.new(config).to_s
26
- end
27
- end
28
- end
29
- end
30
- end