Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make builder work with frozen strings #78

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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