Module: Trailblazer::Generator::Macro

Defined in:
lib/trailblazer/generator/macro.rb

Constant Summary collapse

REGEXP =
/^[A-Z][A-Za-z]{1,}(::[A-Z][A-Za-z]{1,})?/
ERROR_INVALID_CLASS_NAME =

Plase, keep error codes sorted alphabetically

1

Class Method Summary collapse

Class Method Details

.FailureObject



28
29
30
31
32
33
34
35
# File 'lib/trailblazer/generator/macro.rb', line 28

def self.Failure()
  step = ->(input, options) do
    puts "Error: " + options['failure_message']
    options['error_code'] ? exit(options['error_code']) : exit(1)
  end

  [ step, name: "failure" ]
end

.OutputObject



20
21
22
23
24
25
26
# File 'lib/trailblazer/generator/macro.rb', line 20

def self.Output()
  step = ->(input, options) do
    Trailblazer::Generator::Output.new(path: options['path'], content: options['content']).save
  end

  [ step, name: "output" ]
end

.ValidateClassNameObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/trailblazer/generator/macro.rb', line 6

def self.ValidateClassName()
  step = ->(input, options) do
    if options["params"][:name].match REGEXP
      true
    else
      options['failure_message'] = 'You provided an invalid class name'
      options['error_code'] = ERROR_INVALID_CLASS_NAME
      false
    end
  end

  [ step, name: "validate_class_name" ]
end