-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hashie::Extensions::Mash::SafeAssignment
This is part 3 of 3 of the to-do list determined in #198.
- Loading branch information
1 parent
1dce1d0
commit 6a2fac9
Showing
6 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Hashie | ||
module Extensions | ||
module Mash | ||
module SafeAssignment | ||
def assign_property(name, value) | ||
fail ArgumentError, "The property #{name} clashes with an existing method." if methods.include?(name) | ||
|
||
self[name] = value | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
describe Hashie::Extensions::Mash::SafeAssignment do | ||
class MashWithSafeAssignment < Hashie::Mash | ||
include Hashie::Extensions::Mash::SafeAssignment | ||
end | ||
|
||
context 'when included in Mash' do | ||
subject { MashWithSafeAssignment.new } | ||
|
||
context 'when attempting to override a method' do | ||
it 'raises an error' do | ||
expect { subject.zip = 'Test' }.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
end |