Class: Mxrb::Scaffold::Generator

Inherits:
Object
  • Object
show all
Includes:
Recipes
Defined in:
lib/mxrb/scaffold/generator.rb

Overview

Creates conventional Ruby-first artifacts and connects missing aggregators. rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: Result

Constant Summary collapse

IDENTIFIER =
/\A[A-Za-z][A-Za-z0-9_]*\z/
RESERVED_ENTITY_NAMES =
%w[Owner ChangedBy CreatedDate ChangedDate].freeze
PAGE_CHAINS =
%w[page:microflow page:nanoflow page:nanoflow:microflow].freeze
LAYER_AGGREGATORS =
{
  'domain' => 'model.rb',
  'application' => 'application.rb',
  'presentation' => 'presentation.rb',
  'infrastructure' => 'infrastructure.rb'
}.freeze

Constants included from Recipes

Recipes::INFRASTRUCTURE, Recipes::SIMPLE

Instance Method Summary collapse

Constructor Details

#initialize(kind, name = nil, target: Dir.pwd, dry_run: false, **page_options) ⇒ Generator

Returns a new instance of Generator.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mxrb/scaffold/generator.rb', line 21

def initialize(kind, name = nil, target: Dir.pwd, dry_run: false, **page_options)
  @kind = kind.to_sym
  @name = name.to_s
  @root = File.expand_path(target)
  @transaction = Transaction.new
  @dry_run = dry_run
  @page_chain = page_options.delete(:page_chain)
  @page_template = page_options.delete(:page_template)
  raise ArgumentError, "unknown generator options: #{page_options.keys.join(', ')}" unless
    page_options.empty?
end

Instance Method Details

#scaffoldObject



33
34
35
36
37
38
39
40
41
# File 'lib/mxrb/scaffold/generator.rb', line 33

def scaffold
  send("scaffold_#{@kind}")
  registry = stage_registry unless @dry_run
  @transaction.commit unless @dry_run
  Result.new(
    @root, visible(@transaction.created, registry), visible(@transaction.updated, registry),
    @kind, @name, @dry_run
  )
end