Skip to content

Commit

Permalink
Merge pull request #78 from barthez/builder-fronzen-string-fix
Browse files Browse the repository at this point in the history
Make builder work with frozen strings
  • Loading branch information
jenseng authored Feb 8, 2019
2 parents af36817 + 2a2bbc4 commit 3e82999
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/hair_trigger/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,11 @@ def maybe_execute(&block)
block.call(self)
raise DeclarationError, "trigger group did not define any triggers" if @triggers.empty?
else
@actions = block.call
(@actions.is_a?(Hash) ? @actions.values : [@actions]).each do |actions|
actions.sub!(/(\s*)\z/, ';\1') if actions && actions !~ /;\s*\z/
end
@actions =
case (actions = block.call)
when Hash then actions.map { |key, action| [key, ensure_semicolon(action)] }.to_h
else ensure_semicolon(actions)
end
end
# only the top-most block actually executes
if !@trigger_group
Expand All @@ -350,6 +351,10 @@ def maybe_execute(&block)
self
end

def ensure_semicolon(action)
action && action !~ /;\s*\z/ ? action.sub(/(\s*)\z/, ';\1') : action
end

def validate_names!
subtriggers = all_triggers(false)
named_subtriggers = subtriggers.select{ |t| t.options[:name] }
Expand Down
7 changes: 7 additions & 0 deletions spec/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def builder(name = nil)
builder.on(:foos).after(:update){ "FOO " }.generate.
grep(/FOO;/).size.should eql(1)
end

it "should work with frozen strings" do
@adapter = MockAdapter.new("mysql")
lambda {
builder.on(:foos).after(:update){ "FOO".freeze }.generate
}.should_not raise_error
end
end

context "comparison" do
Expand Down

0 comments on commit 3e82999

Please sign in to comment.