Class: Ridley::Search
- Inherits:
-
Object
- Object
- Ridley::Search
- Defined in:
- lib/ridley/resources/search.rb
Instance Attribute Summary collapse
- #connection ⇒ Ridley::Connection readonly
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#start ⇒ Object
Returns the value of attribute start.
Class Method Summary collapse
-
.indexes(connection) ⇒ Array<String, Symbol>
Returns an array of possible search indexes to be search on.
Instance Method Summary collapse
-
#initialize(connection, index, query, options = {}) ⇒ Search
constructor
A new instance of Search.
-
#run ⇒ Hash
Executes the built up query on the search’s connection.
Constructor Details
#initialize(connection, index, query, options = {}) ⇒ Search
Returns a new instance of Search.
37 38 39 40 41 42 43 44 45 |
# File 'lib/ridley/resources/search.rb', line 37 def initialize(connection, index, query, = {}) @connection = connection @index = index.to_sym @query = query @sort = [:sort] @rows = [:rows] @start = [:start] end |
Instance Attribute Details
#connection ⇒ Ridley::Connection (readonly)
19 20 21 |
# File 'lib/ridley/resources/search.rb', line 19 def connection @connection end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
20 21 22 |
# File 'lib/ridley/resources/search.rb', line 20 def index @index end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
21 22 23 |
# File 'lib/ridley/resources/search.rb', line 21 def query @query end |
#rows ⇒ Object
Returns the value of attribute rows.
24 25 26 |
# File 'lib/ridley/resources/search.rb', line 24 def rows @rows end |
#sort ⇒ Object
Returns the value of attribute sort.
23 24 25 |
# File 'lib/ridley/resources/search.rb', line 23 def sort @sort end |
#start ⇒ Object
Returns the value of attribute start.
25 26 27 |
# File 'lib/ridley/resources/search.rb', line 25 def start @start end |
Class Method Details
.indexes(connection) ⇒ Array<String, Symbol>
Returns an array of possible search indexes to be search on
13 14 15 |
# File 'lib/ridley/resources/search.rb', line 13 def indexes(connection) connection.get("search").body.collect { |name, _| name } end |
Instance Method Details
#run ⇒ Hash
Executes the built up query on the search’s connection
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ridley/resources/search.rb', line 70 def run response = connection.get(query_uri, ).body case index when :node response[:rows].collect { |row| Node.new(connection, row) } when :role response[:rows].collect { |row| Role.new(connection, row) } when :client response[:rows].collect { |row| Client.new(connection, row) } when :environment response[:rows].collect { |row| Environment.new(connection, row) } else response[:rows] end end |