rawscsi 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191d7e24f624e40fd9fa23e4302ca049dc000997
4
- data.tar.gz: e6c546867bbcc27af129080cae9491da79924e5a
3
+ metadata.gz: 760003135e883d26c8cd64bdd89b9dfbfd4157d9
4
+ data.tar.gz: a8b6715c316df621c23815f5ee39bd40e925af8e
5
5
  SHA512:
6
- metadata.gz: 4420bda7c0da056b5c4fa0f0a4d5029fcc27212b3aab312d5a914e56075d4c537f45bead88808954e5b48e82451d3cd9ccf176c7bd2aaf406d8911405db2d1a9
7
- data.tar.gz: a34736aab813ccde1b89914c4e18b7a80d6e9f0c5d071f5f5cd7d62042f452ca63c54884aa0c0dcfcba1005f133870915c34f99d92a6467294eb8c4f55aa4ce2
6
+ metadata.gz: e3e2bae8a4208571263e67638554b9d05a0009592c2c6a3f87f3d73e065cc0f87876913a6442ce40d0c3bfbfcf5827a942618ebee75a56304441f5243b2de5cb
7
+ data.tar.gz: 6ddc30ae9f1e9e2afcfa696680d05b4312a39f3e08b8c2b3552f4a55759fe847c5eb117055b5ed6918a7a3d3591877df64af0055fc0bbc77d7138e38d1b172af
data/README.md CHANGED
@@ -108,6 +108,13 @@ book_indexer.upload([
108
108
  ```ruby
109
109
  song_indexer.delete([3244, 53452, 5435, 64545, 34342, 4545])
110
110
  # To delete records in the search domain, you just pass an array of ids (the cloud search record id)
111
+
112
+ # you can also pass in an array of active record objects to be deleted
113
+ song_indexer.delete([
114
+ # active record objects
115
+ <id: 4567, title: "Saturdays Reprise", artist: "Cut Copy", album: "Bright Like Neon Love">
116
+ <id: 5456, title: "Common Burn", artist: "Mazzy Star", album: "Seasons of Your Day">
117
+ ])
111
118
  ```
112
119
 
113
120
  ##### Automatically Batches on cloud search's 5Mb Upload Limit
@@ -1,18 +1,29 @@
1
1
  module Rawscsi
2
2
  module IndexHelpers
3
3
  class SdfDelete
4
- attr_reader :id
4
+ attr_reader :obj_or_id
5
5
 
6
- def initialize(id)
7
- @id = id
6
+ def initialize(obj_or_id)
7
+ @obj_or_id = obj_or_id
8
8
  end
9
9
 
10
10
  def build
11
11
  {
12
12
  :type => "delete",
13
- :id => id
13
+ :id => doc_id
14
14
  }
15
15
  end
16
+
17
+ private
18
+ def doc_id
19
+ if obj_or_id.kind_of?(String) || obj_or_id.kind_of?(Numeric)
20
+ obj_or_id
21
+ elsif obj_or_id.kind_of?(Hash)
22
+ obj_or_id[:id]
23
+ else
24
+ "#{obj_or_id.class}_#{obj_or_id.id}"
25
+ end
26
+ end
16
27
  end
17
28
  end
18
29
  end
@@ -7,7 +7,7 @@ module Rawscsi
7
7
  end
8
8
 
9
9
  def build
10
- id_array = @response["hits"]["hit"].map {|h| h["id"].to_i }
10
+ id_array = @response["hits"]["hit"].map {|h| model_id(h["id"]) }
11
11
  return [] if id_array.empty?
12
12
  results =
13
13
  if ActiveRecord::VERSION::MAJOR > 2
@@ -22,6 +22,10 @@ module Rawscsi
22
22
  def klass
23
23
  @model.constantize
24
24
  end
25
+
26
+ def model_id(doc_id)
27
+ doc_id.split('_').last.to_i
28
+ end
25
29
  end
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module Rawscsi
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
data/rawscsi.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  unless RUBY_VERSION == "1.8.7"
29
29
  spec.add_development_dependency "activerecord", "> 2.0"
30
30
  spec.add_dependency "httparty", "~> 0.11"
31
- spec.add_dependency "faraday", "0.9.0"
31
+ spec.add_dependency "faraday", "0.9.1"
32
32
  spec.add_dependency "faraday_middleware"
33
33
  else
34
34
  spec.add_development_dependency "activerecord", "2.0"
@@ -7,5 +7,11 @@ describe Rawscsi::IndexHelpers::SdfDelete do
7
7
  sdf_hash = Rawscsi::IndexHelpers::SdfDelete.new(id).build
8
8
  expect(sdf_hash).to eq({:type => "delete", :id => 4})
9
9
  end
10
+
11
+ it "constructs an sdf delete json for an active record object" do
12
+ obj = Movie.new(293428934, "Slingblade", ["Billy Bob Thorton", "Dwight Yokam"], 9)
13
+ sdf_hash = Rawscsi::IndexHelpers::SdfDelete.new(obj).build
14
+ expect(sdf_hash).to eq({:type => "delete", :id => "Movie_293428934"})
15
+ end
10
16
  end
11
17
 
@@ -41,7 +41,7 @@ describe Rawscsi::Search do
41
41
  it "performs a search with specified return fields" do
42
42
  VCR.use_cassette("search_spec/fields") do
43
43
  results = @search_helper.search(:q => {:and => [{:title => "Die Hard"}]}, :fields => [:title, :genres])
44
- expect(results).to include({"genres"=>["Action", "Thriller"], "title" => "Die Hard", "id" => "tt0095016"})
44
+ expect(results).to include({"genres"=>["Action", "Thriller"], "title" => "Die Hard", "id"=>"tt0095016"})
45
45
  expect(results).to include({"genres"=>["Action", "Thriller"], "title" => "Die Hard 2", "id"=>"tt0099423"})
46
46
  end
47
47
  end
@@ -52,7 +52,7 @@ describe Rawscsi::Search do
52
52
  results = @search_helper.search(:q => {:and => [{:actors => "Kevin Bacon"}, {:actors => "Tom Hanks"}]},
53
53
  :fields => [:title])
54
54
 
55
- expect(results).to eq([{"title" => "Apollo 13", "id"=>"tt0112384"}])
55
+ expect(results).to eq([{"title"=>"Apollo 13", "id"=>"tt0112384"}])
56
56
  end
57
57
  end
58
58
 
@@ -77,7 +77,7 @@ describe Rawscsi::Search do
77
77
  },
78
78
  :fields => [:title])
79
79
  expect(results).to eq([{"title"=>"The Terminator", "id"=>"tt0088247"},
80
- {"title"=>"Terminator 2: Judgment Day", "id"=>"tt0103064"}])
80
+ {"title"=>"Terminator 2: Judgment Day", "id"=>"tt0103064" }])
81
81
  end
82
82
  end
83
83
 
@@ -89,10 +89,9 @@ describe Rawscsi::Search do
89
89
  :limit => 3,
90
90
  :fields => [:title])
91
91
  expect(results).to eq([
92
- {"title"=>"Star Wars: Episode V - The Empire Strikes Back", "id"=>"tt0080684"},
93
- {"title"=>"Inception", "id"=>"tt1375666"},
94
- {"title"=>"The Matrix", "id"=>"tt0133093"}
95
- ])
92
+ {"title"=> "Star Wars: Episode V - The Empire Strikes Back", "id"=>"tt0080684"},
93
+ {"title"=>"Inception", "id"=>"tt1375666"},
94
+ {"title"=>"The Matrix", "id"=>"tt0133093"}])
96
95
  end
97
96
  end
98
97
 
@@ -102,18 +101,20 @@ describe Rawscsi::Search do
102
101
  results = @search_helper.search(:q => {:and => [{:plot => "James Bond"}]},
103
102
  :date => { :release_date => "['1970-01-01',}" },
104
103
  :fields => [:title])
105
- expect(results).to eq([
106
- {"title"=>"Moonraker", "id"=>"tt0079574"},
107
- {"title"=>"Never Say Never Again", "id"=>"tt0086006"},
108
- {"title"=>"The Living Daylights", "id"=>"tt0093428"},
109
- {"title"=>"Tomorrow Never Dies", "id"=>"tt0120347"},
110
- {"title"=>"The World Is Not Enough", "id"=>"tt0143145"},
111
- {"title"=>"GoldenEye", "id"=>"tt0113189"},
112
- {"title"=>"Diamonds Are Forever", "id"=>"tt0066995"},
113
- {"title"=>"The Spy Who Loved Me", "id"=>"tt0076752"},
114
- {"title"=>"Die Another Day", "id"=>"tt0246460"},
115
- {"title"=>"Octopussy", "id"=>"tt0086034"}
116
- ])
104
+ expect(results).to eq(
105
+ [
106
+ {"title"=>"Moonraker", "id"=>"tt0079574"},
107
+ {"title"=>"Never Say Never Again", "id"=>"tt0086006"},
108
+ {"title"=>"The Living Daylights", "id"=>"tt0093428"},
109
+ {"title"=>"Tomorrow Never Dies", "id"=>"tt0120347"},
110
+ {"title"=>"The World Is Not Enough", "id"=>"tt0143145"},
111
+ {"title"=>"GoldenEye", "id"=>"tt0113189"},
112
+ {"title"=>"Diamonds Are Forever", "id"=>"tt0066995"},
113
+ {"title"=>"The Spy Who Loved Me", "id"=>"tt0076752"},
114
+ {"title"=>"Die Another Day", "id"=>"tt0246460"},
115
+ {"title"=>"Octopussy", "id"=>"tt0086034"}
116
+ ]
117
+ )
117
118
  end
118
119
  end
119
120
 
@@ -128,18 +129,12 @@ describe Rawscsi::Search do
128
129
  :sort => "rating desc",
129
130
  :fields => [:title],
130
131
  :limit => 10)
131
- expect(results).to eq([
132
- {"title"=>"Léon", "id"=>"tt0110413"},
133
- {"title"=>"The Deer Hunter", "id"=>"tt0077416"},
134
- {"title"=>"In the Name of the Father", "id"=>"tt0107207"},
135
- {"title"=>"The Graduate", "id"=>"tt0061722"},
136
- {"title"=>"There Will Be Blood", "id"=>"tt0469494"},
137
- {"title"=>"Papillon", "id"=>"tt0070511"},
138
- {"title"=>"All the President's Men", "id"=>"tt0074119"},
139
- {"title"=>"Rain Man", "id"=>"tt0095953"},
140
- {"title"=>"JFK", "id"=>"tt0102138"},
141
- {"title"=>"Midnight Cowboy", "id"=>"tt0064665"}
142
- ])
132
+ expect(results).to include({"title"=>"The Deer Hunter", "id"=>"tt0077416"})
133
+ expect(results).to include({"title"=>"In the Name of the Father", "id"=>"tt0107207"})
134
+ expect(results).to include({"title"=>"The Graduate", "id"=>"tt0061722"})
135
+ expect(results).to include({"title"=>"There Will Be Blood", "id"=>"tt0469494"})
136
+ expect(results).to include({"title"=>"Papillon", "id"=>"tt0070511" })
137
+ expect(results).to include({"title"=>"All the President's Men", "id"=>"tt0074119"})
143
138
  end
144
139
  end
145
140
 
@@ -156,18 +151,20 @@ describe Rawscsi::Search do
156
151
  :sort => "rating desc",
157
152
  :fields => [:title],
158
153
  :limit => 10)
159
- expect(results).to eq([
160
- {"title"=>"Terminator 2: Judgment Day", "id"=>"tt0103064"},
161
- {"title"=>"The Terminator", "id"=>"tt0088247"},
162
- {"title"=>"Predator", "id"=>"tt0093773"},
163
- {"title"=>"First Blood", "id"=>"tt0083944"},
164
- {"title"=>"Watchmen", "id"=>"tt0409459"},
165
- {"title"=>"Escape Plan", "id"=>"tt1211956"},
166
- {"title"=>"Jui kuen II", "id"=>"tt0111512"},
167
- {"title"=>"Total Recall", "id"=>"tt0100802"},
168
- {"title"=>"Kung Fu Panda 2", "id"=>"tt1302011"},
169
- {"title"=>"True Lies", "id"=>"tt0111503"}
170
- ])
154
+ expect(results).to eq(
155
+ [
156
+ {"title"=>"Terminator 2: Judgment Day", "id"=>"tt0103064"},
157
+ {"title"=>"The Terminator", "id"=>"tt0088247"},
158
+ {"title"=>"Predator", "id"=>"tt0093773"},
159
+ {"title"=>"First Blood", "id"=>"tt0083944"},
160
+ {"title"=>"Watchmen", "id"=>"tt0409459"},
161
+ {"title"=>"Escape Plan", "id"=>"tt1211956"},
162
+ {"title"=>"Jui kuen II", "id"=>"tt0111512"},
163
+ {"title"=>"Total Recall", "id"=>"tt0100802"},
164
+ {"title"=>"Kung Fu Panda 2", "id"=>"tt1302011"},
165
+ {"title"=>"True Lies", "id"=>"tt0111503"}
166
+ ]
167
+ )
171
168
  end
172
169
  end
173
170
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rawscsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.9.0
131
+ version: 0.9.1
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.9.0
138
+ version: 0.9.1
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: faraday_middleware
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  requirements: []
221
221
  rubyforge_project:
222
- rubygems_version: 2.4.2
222
+ rubygems_version: 2.2.2
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: Adds service objects to upload and search active record models with AWS Cloud