gummi 0.1.0 → 0.1.1

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.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p484
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in gummi.gemspec
4
3
  gemspec
5
4
 
6
- gem "codeclimate-test-reporter", group: :test, require: nil
5
+ group :development, :test do
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
7
+ gem 'guard-bundler', '2.0.0'
8
+ gem 'guard-rspec', '4.0.4'
9
+ gem 'timecop', '0.7.0'
10
+ end
data/Guardfile ADDED
@@ -0,0 +1,31 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :bundler do
5
+ watch('Gemfile')
6
+ # Uncomment next line if your Gemfile contains the `gemspec' command.
7
+ # watch(/^.+\.gemspec/)
8
+ end
9
+
10
+ guard :rspec, cmd: 'rspec --fail-fast' do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+
15
+ # Rails example
16
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
17
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
18
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
19
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
20
+ watch('config/routes.rb') { "spec/routing" }
21
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
22
+
23
+ # Capybara features specs
24
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
25
+
26
+ # Turnip features and steps
27
+ watch(%r{^spec/acceptance/(.+)\.feature$})
28
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
29
+ end
30
+
31
+
data/lib/gummi/api.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Gummi
2
2
  module API
3
3
  def self.client
4
- @client ||= ::Elasticsearch::Client.new log: false
4
+ @client ||= ::Elasticsearch::Client.new log: true
5
5
  end
6
6
  end
7
7
  end
data/lib/gummi/entity.rb CHANGED
@@ -8,5 +8,13 @@ module Gummi
8
8
 
9
9
  attr_accessor :id
10
10
  attr_accessor :version
11
+
12
+ def ==(other)
13
+ other &&
14
+ self.id == other.id &&
15
+ self.version == other.version &&
16
+ self.attributes == other.attributes
17
+ end
18
+
11
19
  end
12
- end
20
+ end
@@ -2,7 +2,7 @@ module Gummi
2
2
  module Repository
3
3
  class Result
4
4
 
5
- attr_reader :took, :total, :hits, :facets
5
+ attr_reader :took, :total, :hits
6
6
 
7
7
  def initialize(db_result, repository, per_page, page)
8
8
  @took = db_result.took
@@ -15,6 +15,12 @@ module Gummi
15
15
  @page = page
16
16
  end
17
17
 
18
+ def facets
19
+ @facets.each_with_object({}) do |(name, content), facets|
20
+ facets[name] = Hash[content["terms"].collect{|term| term.values}]
21
+ end
22
+ end
23
+
18
24
  def records
19
25
  entities = Array(@repository.to_entity_from_db(@db_records)) if @db_records
20
26
  Leaflet::Collection.new entities, page: @page, total: total, per_page: @per_page
data/lib/gummi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gummi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -9,4 +9,4 @@ module Repobahn
9
9
  end
10
10
 
11
11
  end
12
- end
12
+ end
@@ -54,4 +54,4 @@ module Repobahn
54
54
  end
55
55
  end
56
56
  end
57
- end
57
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- class ExampleModel
3
+ class GummiDummyDocument
4
4
  include Gummi::Document
5
5
 
6
6
  attribute :test, String
@@ -9,14 +9,14 @@ end
9
9
  describe Gummi::Document do
10
10
 
11
11
  context "included" do
12
- it "should add accessors for id and version" do
13
- m = ExampleModel.new
12
+ it "adds accessors for id and version" do
13
+ m = GummiDummyDocument.new
14
14
  m.respond_to?(:version).should be_true
15
15
  m.respond_to?(:id).should be_true
16
16
  end
17
17
 
18
- it "should add attributes methods" do
19
- m = ExampleModel.new(test: 'hello')
18
+ it "adds attributes methods" do
19
+ m = GummiDummyDocument.new(test: 'hello')
20
20
  m.test.should == 'hello'
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ describe Gummi::Document do
24
24
  context "attributes" do
25
25
 
26
26
  context "date times" do
27
- it "should coerce from elastics strings to real Time" do
27
+ it "coerces from elastics strings to real Time" do
28
28
  time = Time.now
29
29
  person = DB::Person.new(born_at: time)
30
30
  person.overwrite
@@ -32,7 +32,7 @@ describe Gummi::Document do
32
32
  person_from_es.born_at.should be_a Time
33
33
  end
34
34
 
35
- it "should always store time in UTC" do
35
+ it "always stores time in UTC" do
36
36
  time = Time.now.in_time_zone 'CET'
37
37
 
38
38
  person = DB::Person.new(born_at: time)
@@ -44,19 +44,19 @@ describe Gummi::Document do
44
44
 
45
45
  let(:person) { DB::Person.new}
46
46
 
47
- it "should add them to the attributes hash" do
47
+ it "adds them to the attributes hash" do
48
48
  person.name = "olof palme"
49
49
  person.attributes[:computed_name].should == 'OLOF PALME'
50
50
  end
51
51
 
52
- it "should compute every time" do
52
+ it "computes every time" do
53
53
  person.name = "olof palme"
54
54
  person.computed_name.should == person.name.upcase
55
55
  person.name = "carl bildt"
56
56
  person.computed_name.should == person.name.upcase
57
57
  end
58
58
 
59
- it "should provide a mapping" do
59
+ it "provides a mapping" do
60
60
  DB::Person.mapping.should include(:computed_name => {:type=>"string"})
61
61
  end
62
62
  end
@@ -65,9 +65,9 @@ describe Gummi::Document do
65
65
  context 'getting from elastic' do
66
66
  let (:person) { DB::Person.create(name: 'Buzz Lightyear') }
67
67
 
68
- it "should return an instance of the db_model" do
68
+ it "returns an instance of the db_model" do
69
69
  person_from_es = DB::Person.get(person.id)
70
70
  person_from_es.should be_a DB::Person
71
71
  end
72
72
  end
73
- end
73
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gummi::Entity do
4
+
5
+ context 'comparison' do
6
+ let(:car) { Person::Car.new model: 'Blues Mobile' }
7
+ let (:jake1) { Person.new id: 'abcdef', version: 1, name: 'Jake', born_at: 100.years.ago, car: car }
8
+ let (:jake2) { Person.new id: 'abcdef', version: 1, name: 'Jake', born_at: 100.years.ago, car: car }
9
+ let (:jake3) { Person.new id: 'ghijgk', version: 1, name: 'Jake', born_at: 100.years.ago, car: car }
10
+ let (:jake4) { Person.new id: 'abcdef', version: 1, name: 'John', born_at: 100.years.ago, car: car }
11
+ let (:jake5) { Person.new id: 'abcdef', version: 2, name: 'Jake', born_at: 100.years.ago, car: car }
12
+ let (:jake6) { Person.new id: 'abcdef', version: 1, name: 'Jake', born_at: 100.years.ago, car: Person::Car.new(model: 'Blues Mobile') }
13
+ let (:jake7) { Person.new id: 'abcdef', version: 2, name: 'Jake', born_at: 100.years.ago, car: Person::Car.new(model: 'Police Car') }
14
+
15
+ it 'recognizes equal objects' do
16
+ jake1.should == jake2
17
+ end
18
+
19
+ it 'recognizes different ids' do
20
+ jake1.should_not == jake3
21
+ end
22
+
23
+ it 'recognizes different attributes' do
24
+ jake1.should_not == jake4
25
+ end
26
+
27
+ it 'recognizes different versions' do
28
+ jake1.should_not == jake5
29
+ end
30
+
31
+ it 'recognizes equal submodel instances' do
32
+ jake1.should == jake6
33
+ end
34
+
35
+ it 'recognizes different submodel attributes' do
36
+ jake1.should_not == jake7
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gummi::Repository::Result do
4
+
5
+ describe "#facets" do
6
+ it "returns the relevant terms with counts" do
7
+ db_result = OpenStruct.new(facets: {"categories"=>
8
+ {"_type"=>"terms",
9
+ "missing"=>0,
10
+ "total"=>3,
11
+ "other"=>0,
12
+ "terms"=>[{"term"=>"design", "count"=>2}, {"term"=>"silver", "count"=>1}]}})
13
+
14
+ result = Gummi::Repository::Result.new(db_result, nil, nil, nil)
15
+ result.facets.should == {"categories" => {"design" => 2, "silver" => 1}}
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,16 @@
1
1
  # example entity model
2
2
  class Person
3
+
4
+ class Car
5
+ include Gummi::Entity
6
+
7
+ attribute :model, String
8
+ end
9
+
3
10
  include Gummi::Entity
4
11
 
5
12
  attribute :name, String
6
13
  attribute :converted_name, String
7
- end
14
+ attribute :car, Car
15
+
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gummi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-25 00:00:00.000000000 Z
12
+ date: 2013-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus
@@ -179,7 +179,10 @@ extensions: []
179
179
  extra_rdoc_files: []
180
180
  files:
181
181
  - .gitignore
182
+ - .rspec
183
+ - .ruby-version
182
184
  - Gemfile
185
+ - Guardfile
183
186
  - LICENSE.txt
184
187
  - README.md
185
188
  - Rakefile
@@ -212,6 +215,8 @@ files:
212
215
  - lib/repobahn/entity.rb
213
216
  - lib/repobahn/repository.rb
214
217
  - spec/lib/gummi/document_spec.rb
218
+ - spec/lib/gummi/entity_spec.rb
219
+ - spec/lib/gummi/repository/result_spec.rb
215
220
  - spec/lib/gummi/repository_spec.rb
216
221
  - spec/models/db/person.rb
217
222
  - spec/models/people.rb
@@ -230,18 +235,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
235
  - - ! '>='
231
236
  - !ruby/object:Gem::Version
232
237
  version: '0'
233
- segments:
234
- - 0
235
- hash: 2387628349001688798
236
238
  required_rubygems_version: !ruby/object:Gem::Requirement
237
239
  none: false
238
240
  requirements:
239
241
  - - ! '>='
240
242
  - !ruby/object:Gem::Version
241
243
  version: '0'
242
- segments:
243
- - 0
244
- hash: 2387628349001688798
245
244
  requirements: []
246
245
  rubyforge_project:
247
246
  rubygems_version: 1.8.23
@@ -250,6 +249,8 @@ specification_version: 3
250
249
  summary: A small wrapper around Elasticsearch
251
250
  test_files:
252
251
  - spec/lib/gummi/document_spec.rb
252
+ - spec/lib/gummi/entity_spec.rb
253
+ - spec/lib/gummi/repository/result_spec.rb
253
254
  - spec/lib/gummi/repository_spec.rb
254
255
  - spec/models/db/person.rb
255
256
  - spec/models/people.rb