Skip to content

Commit

Permalink
Add support for lambda key converters.
Browse files Browse the repository at this point in the history
This is the quick solution.
  • Loading branch information
tvon-a committed Dec 1, 2014
1 parent 985a61d commit fba6601
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/gyoku/xml_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def create(key, options = {})

# Returns the formula for converting Symbol keys.
def key_converter(options, xml_key)
return options[:key_converter] if options[:key_converter].is_a? Proc

defined_key = options[:key_to_convert]
if (defined_key != nil) && (defined_key == xml_key)
key_converter = options[:key_converter]
Expand Down
4 changes: 4 additions & 0 deletions spec/gyoku/xml_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
end

context "with key_converter" do
it "accepts lambda converters" do
expect(create(:some_text, {key_converter: -> (k) { k.reverse }})).to eq("txet_emos")
end

it "convert symbol to the specified type" do
expect(create(:some_text, {key_converter: :camelcase})).to eq("SomeText")
expect(create(:some_text, {key_converter: :upcase})).to eq("SOME_TEXT")
Expand Down

0 comments on commit fba6601

Please sign in to comment.