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

Allow unwrap option to whitelist keys. #54

Merged
merged 5 commits into from
Mar 4, 2016
Merged

Conversation

rlburkes
Copy link
Contributor

@rlburkes rlburkes commented Apr 6, 2015

Recently this PR was merged to allow unwrapping of arrays. This capability is awesome and I am excited it landed. However, I recently had a use case that required me to unwrap only certain keys. These changes support whitelisting keys to unwrap. The option supports either an array of keys (symbols) to unwrap or a boolean value for wholesale unwrap/wrap behavior.

Unwrapping Arrays. You can specify an optional unwrap argument to modify the default Array
behavior. unwrap accepts a boolean flag (false by default) or an Array whitelist of keys to unwrap.

# Default Array behavior
Gyoku.xml({
  "foo" => [
    {:is => 'great' },
    {:is => 'awesome'}
  ]
})
# => "<foo><is>great</is></foo><foo><is>awesome</is></foo>"

# Unwrap Array behavior
Gyoku.xml({
  "foo" => [
    {:is => 'great' },
    {:is => 'awesome'}
  ]
}, unwrap: true)
# => "<foo><is>great</is><is>awesome</is></foo>"

# Unwrap Array, whitelist.
# foo is not unwrapped, bar is.
Gyoku.xml({
  "foo" => [
    {:is => 'great' },
    {:is => 'awesome'}
  ],
  "bar" => [
      {:is => 'rad' },
      {:is => 'cool'}
  ]
}, unwrap: [:bar])
# => "<foo><is>great</is></foo><foo><is>awesome</is></foo><bar><is>rad</is><is>cool</is></bar>"

Thanks for this awesome Gem. If you have any concerns with overloading this option I am open to any suggestions. I added some doc to the readme, I included a section on the new(er) key_converter functionality as it is something I found useful that wasn't included.

mahemoff added a commit to mahemoff/gyoku that referenced this pull request Dec 24, 2015
Array serialization in Gyoku confused me until I discovered savonrb#52 and
looked at the test case. This doco should help. Note it doesn't document
the further enhancement in savonrb#54,  which is not yet merged.
mahemoff added a commit to mahemoff/gyoku that referenced this pull request Dec 24, 2015
Array serialization in Gyoku confused me until I discovered savonrb#52 and
looked at the test case. This doco should help. Note it doesn't document
the further enhancement in savonrb#54,  which is not yet merged.
mahemoff added a commit to mahemoff/gyoku that referenced this pull request Dec 24, 2015
Array serialization in Gyoku confused me until I discovered savonrb#52 and
looked at the test case. This doco should help. Note it doesn't document
the further enhancement in savonrb#54,  which is not yet merged.
tjarratt added a commit that referenced this pull request Mar 4, 2016
Allow unwrap option to whitelist keys.
@tjarratt tjarratt merged commit 915585c into savonrb:master Mar 4, 2016
@tjarratt
Copy link
Contributor

tjarratt commented Mar 4, 2016

Thanks @rlburkes !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants