Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
robertDurst committed Dec 27, 2023
1 parent bc8dc67 commit 5d55931
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 191 deletions.
49 changes: 49 additions & 0 deletions spec/examples/rails_job_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require 'rails/generators/named_base'

module Rails # :nodoc:
module Generators # :nodoc:
class JobGenerator < Rails::Generators::NamedBase # :nodoc:
class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job'

class_option :parent, type: :string, default: 'ApplicationJob', desc: 'The parent class for the generated job'

check_class_collision suffix: 'Job'

hook_for :test_framework

def self.default_generator_root
__dir__
end

def create_job_file
template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb")

in_root do
if behavior == :invoke && !File.exist?(application_job_file_name)
template 'application_job.rb', application_job_file_name
end
end
end

private

def parent_class_name
options[:parent]
end

def file_name
@file_name ||= super.sub(/_job\z/i, '')
end

def application_job_file_name
@application_job_file_name ||= if mountable_engine?
"app/jobs/#{namespaced_path}/application_job.rb"
else
'app/jobs/application_job.rb'
end
end
end
end
end
25 changes: 25 additions & 0 deletions spec/zodiac/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@

expect(lexer.lex).to eq(expected_output)
end

# file:
it 'lexs a full ruby program without throwing and returns' do
input = File.read('./spec/examples/rails_job_generator.rb')
lexer = described_class.new(input)

expect(lexer.lex.size).to be > 0
end

it 'lexs comments' do
input = <<~RUBY
# this is a comment
# this is another comment
# this is a third comment
RUBY
lexer = described_class.new(input)

expected_output = [
{ kind: 'COMMENT', value: '# this is a comment' },
{ kind: 'COMMENT', value: '# this is another comment' },
{ kind: 'COMMENT', value: '# this is a third comment' }
]

expect(lexer.lex).to eq(expected_output)
end
end
end
end
16 changes: 16 additions & 0 deletions src/zodiac/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def lex_next
end
@tokens << { kind: 'SYMBOL', value: word }
end
elsif @cur == '#'
lex_comment
elsif symbol?(@cur) && !@raw_string[@cur_index + 2].nil? && @raw_string[@cur_index..@cur_index + 2] == '<=>'
@tokens << { kind: 'SYMBOL', value: '<=>' }
@cur_index += 3
Expand Down Expand Up @@ -150,5 +152,19 @@ def lex_identifier

@tokens << { kind: 'IDENTIFIER', value: word }
end

def lex_comment
word = '#'
@cur_index += 1
@cur = @raw_string[@cur_index]

while @cur != "\n"
word += @cur
@cur_index += 1
@cur = @raw_string[@cur_index]
end

@tokens << { kind: 'COMMENT', value: word }
end
end
end
Loading

0 comments on commit 5d55931

Please sign in to comment.