Class: Wukong::Elasticsearch::IndexAndMapping
- Inherits:
-
Object
- Object
- Wukong::Elasticsearch::IndexAndMapping
- Defined in:
- lib/wonderdog/index_and_mapping.rb
Overview
A convenient class for parsing Elasticsearch index and mapping URIs like
- es://my_index
- es://my_index/my_mapping
- es://first_index,second_index,third_index
- es://my_index/first_mapping,second_mapping,third_mapping
Constant Summary collapse
- ES_SCHEME_REGEXP =
A regular expression that matches URIs describing an Elasticsearch index and/or mapping to read/write from/to.
%r{^es://}
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
The Elasticsearch index.
-
#mapping ⇒ Object
readonly
The Elasticsearch mapping.
Class Method Summary collapse
-
.matches?(string) ⇒ true, false
Does the given
string
look like a possible Elasticsearch /index/mapping specification?.
Instance Method Summary collapse
-
#initialize(uri) ⇒ IndexAndMapping
constructor
Create a new index and mapping specification from the given +uri..
-
#uri=(uri) ⇒ Object
Set the URI of this index and mapping specification, parsing it for an index and mapping.
Constructor Details
#initialize(uri) ⇒ IndexAndMapping
Create a new index and mapping specification from the given +uri..
43 44 45 |
# File 'lib/wonderdog/index_and_mapping.rb', line 43 def initialize uri self.uri = uri end |
Instance Attribute Details
#index ⇒ Object (readonly)
The Elasticsearch index.
22 23 24 |
# File 'lib/wonderdog/index_and_mapping.rb', line 22 def index @index end |
#mapping ⇒ Object (readonly)
The Elasticsearch mapping.
27 28 29 |
# File 'lib/wonderdog/index_and_mapping.rb', line 27 def mapping @mapping end |
Class Method Details
.matches?(string) ⇒ true, false
Does the given string
look like a possible Elasticsearch
/index/mapping specification?
34 35 36 37 |
# File 'lib/wonderdog/index_and_mapping.rb', line 34 def self.matches? string return false unless string string =~ ES_SCHEME_REGEXP end |
Instance Method Details
#uri=(uri) ⇒ Object
Set the URI of this index and mapping specification, parsing it for an index and mapping.
Will raise an error if the given URI is malformed.
53 54 55 56 57 58 59 60 61 |
# File 'lib/wonderdog/index_and_mapping.rb', line 53 def uri= uri raise Wukong::Error.new("'#{uri}' is not an ElasticSearch es://index/mapping specification") unless self.class.matches?(uri) parts = uri.gsub(ES_SCHEME_REGEXP, '').gsub(/^\/+/,'').gsub(/\/+$/,'').split('/') raise Wukong::Error.new("'#{uri}' is not an ElasticSearch es://index/mapping specification") unless parts.size.between?(1,2) @index = parts[0] @mapping = parts[1] end |