Skip to content

Instantly share code, notes, and snippets.

@woahdae
Created January 19, 2012 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woahdae/1637161 to your computer and use it in GitHub Desktop.
Save woahdae/1637161 to your computer and use it in GitHub Desktop.
alternate indexes implementation
# leaves around a pointer to the root mapping after use
def indexes(name, options = {}, &block)
@_mapping_pointer ||= @mapping
@_mapping_pointer[name] = options
if block_given?
previous = @_mapping_pointer
@_mapping_pointer[name][:type] ||= 'object'
@_mapping_pointer = @_mapping_pointer[name][:properties] = {}
yield
@_mapping_pointer = previous
end
@_mapping_pointer[name][:type] ||= 'string'
self
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment