lib/generators/rider_kick/scaffold_generator.rb in rider-kick-0.0.3 vs lib/generators/rider_kick/scaffold_generator.rb in rider-kick-0.0.4
- old
+ new
@@ -2,10 +2,11 @@
module RiderKick
class ScaffoldGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)
argument :arg_structure, type: :string, default: '', banner: ''
+ argument :arg_scope, type: :hash, default: '', banner: 'scope:dashboard'
def generate_use_case
validation!
setup_variables
@@ -19,13 +20,13 @@
end
private
def validation!
- unless File.exist?('config/initializers/rider_kick.rb')
- say 'Error must create init configuration for rider_kick!'
- raise Thor::Error, 'run: bin/rails generate rider_kick:init'
+ unless Dir.exist?('app/domains')
+ say 'Error must create clean arch structure first!'
+ raise Thor::Error, 'run: bin/rails generate rider_kick:clean_arch --setup'
end
end
def setup_variables
config = YAML.load_file("db/structures/#{arg_structure}_structure.yaml")
@@ -52,11 +53,11 @@
@scope_path = resource_name.pluralize.underscore.downcase
@scope_class = @scope_path.camelize
@model_class = model_name.camelize.constantize
@subject_class = resource_name.camelize
@fields = contract_fields
- @route_scope_path = @structure.controllers.route_scope.downcase rescue ''
+ @route_scope_path = arg_scope['scope'].to_s.downcase rescue ''
@route_scope_class = @route_scope_path.camelize rescue ''
@type_mapping = {
'uuid' => ':string',
'string' => ':string',
@@ -98,11 +99,11 @@
template 'domains/core/entities/entity.rb.tt', File.join("#{root_path_app}/domains/core/entities", "#{@variable_subject}.rb")
end
def contract_fields
skip_contract_fields = @skipped_fields.map(&:strip).uniq
- if RiderKick.scope_owner_column.present?
- skip_contract_fields << RiderKick.scope_owner_column.to_s
+ if @scope_owner_column.present?
+ skip_contract_fields << @scope_owner_column.to_s
end
@model_class.columns.reject { |column| skip_contract_fields.include?(column.name.to_s) }.map(&:name).map(&:to_s)
end
def get_column_type(field)