Sha256: 446a16b49535e7159e2bd7ced976ace35c1d9de39b6ecde04281cba8aaa9889c

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require_relative "wizard/version"
require_relative "wizard/concept_type"
require_relative "wizard/concept_generator"
require_relative "wizard/file_helper"
require_relative "wizard/configuration"

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

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

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

  def self.configure
    yield(configuration)
  end

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-wizard-0.0.5 lib/wizard.rb