Class: TrailblazerWizard::ConceptGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer_wizard/concept_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ConceptGenerator

Returns a new instance of ConceptGenerator.



9
10
11
# File 'lib/trailblazer_wizard/concept_generator.rb', line 9

def initialize(**args)\
  @type = args[:type]
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/trailblazer_wizard/concept_generator.rb', line 7

def type
  @type
end

Instance Method Details

#generate(model, name, context = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/trailblazer_wizard/concept_generator.rb', line 17

def generate(model, name, context = nil)
  materials = [model, type_dirname, name]
  materials.insert(1, context) unless context.nil?

  filename = materials.map { |material| ActiveSupport::Inflector.underscore(material) }.join("/")
  filename = "#{TrailblazerWizard.configuration.base_directory}/#{filename}.rb"

  false if File.exist?(filename)

  content = copy(model, name, context)
  create_file(filename, content)

  filename
end

#true_typeObject



13
# File 'lib/trailblazer_wizard/concept_generator.rb', line 13

def true_type = (TrailblazerWizard.configuration.alt_types[type.to_sym] || type).to_s

#type_dirnameObject



15
# File 'lib/trailblazer_wizard/concept_generator.rb', line 15

def type_dirname = TrailblazerWizard.configuration.pluralize ? ActiveSupport::Inflector.pluralize(true_type) : true_type