Module: TrailblazerWizard

Defined in:
lib/wizard.rb,
lib/trailblazer_wizard/version.rb,
lib/trailblazer_wizard/file_helper.rb,
lib/trailblazer_wizard/concept_type.rb,
lib/trailblazer_wizard/configuration.rb,
lib/trailblazer_wizard/concept_generator.rb

Defined Under Namespace

Modules: ConceptType Classes: ConceptGenerator, Configuration, FileHelper

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.configurationObject



18
19
20
# File 'lib/wizard.rb', line 18

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



22
23
24
# File 'lib/wizard.rb', line 22

def self.configure
  yield(configuration)
end

.fetch_generator(type) ⇒ Object



14
15
16
# File 'lib/wizard.rb', line 14

def self.fetch_generator(type)
  pool[type] ||= ConceptGenerator.new(type: type)
end

.generate(model, **args) ⇒ Object

Raises:

  • (StandardError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wizard.rb', line 26

def self.generate(model, **args)
  raise StandardError, "[model] arg is required" if model.nil?

  raise StandardError, "[actions] arg is required" unless args.key? :actions

  concepts = ConceptType::ALL.values
  actions = args[:actions]

  concepts -= args[:except] if args.key? :except
  concepts = args[:only]    if args.key? :only

  output = []

  actions.each do |action|
    concepts.each do |concept|
      file = fetch_generator(concept.to_s).generate(model, action.to_s, args[:context]&.to_s)
      output << file if file.length.positive?
    end
  end

  output
end

.poolObject



10
11
12
# File 'lib/wizard.rb', line 10

def self.pool
  @pool ||= {}
end