kosher 0.11.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/kosher.gemspec +1 -1
- data/lib/kosher/detail.rb +18 -0
- data/lib/kosher/filter.rb +12 -0
- data/lib/kosher/offer.rb +13 -6
- data/lib/kosher/price.rb +3 -0
- data/lib/kosher/seller.rb +5 -3
- data/lib/kosher/shipping.rb +2 -1
- data/lib/kosher/unit.rb +2 -14
- data/lib/kosher/venue.rb +27 -5
- data/lib/kosher/version.rb +1 -1
- data/lib/kosher.rb +18 -2
- data/test/kosher_test.rb +17 -11
- metadata +15 -14
- data/lib/kosher/base.rb +0 -18
data/kosher.gemspec
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kosher
|
2
|
+
class Detail < Structure
|
3
|
+
include Filter
|
4
|
+
|
5
|
+
key :condition, Integer
|
6
|
+
key :description, String, :default => ''
|
7
|
+
|
8
|
+
validates_inclusion_of :condition, :in => 1..6
|
9
|
+
|
10
|
+
def new?
|
11
|
+
condition == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def used?
|
15
|
+
!new?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/kosher/offer.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'certainty'
|
2
|
+
|
3
|
+
require 'kosher/filter'
|
2
4
|
require 'kosher/price'
|
3
5
|
|
6
|
+
require 'kosher/detail'
|
4
7
|
require 'kosher/seller'
|
5
8
|
require 'kosher/shipping'
|
6
9
|
require 'kosher/unit'
|
@@ -10,12 +13,15 @@ module Kosher
|
|
10
13
|
class Offer < Structure
|
11
14
|
include Comparable
|
12
15
|
|
13
|
-
key :id
|
14
|
-
key :
|
15
|
-
key :
|
16
|
-
key :
|
16
|
+
key :id, String
|
17
|
+
key :detail, Detail
|
18
|
+
key :seller, Seller
|
19
|
+
key :shipping, Shipping
|
20
|
+
key :unit, Unit
|
17
21
|
key :venue_id, Integer
|
18
22
|
|
23
|
+
validates_presence_of :detail, :seller, :shipping, :unit, :venue
|
24
|
+
|
19
25
|
def <=>(other)
|
20
26
|
if kosher? != other.kosher?
|
21
27
|
kosher? ? -1 : 1
|
@@ -25,7 +31,8 @@ module Kosher
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def kosher?
|
28
|
-
|
34
|
+
validate!
|
35
|
+
[seller, shipping, detail].all?(&:kosher?)
|
29
36
|
end
|
30
37
|
|
31
38
|
def price
|
data/lib/kosher/price.rb
CHANGED
data/lib/kosher/seller.rb
CHANGED
data/lib/kosher/shipping.rb
CHANGED
data/lib/kosher/unit.rb
CHANGED
@@ -1,19 +1,7 @@
|
|
1
1
|
module Kosher
|
2
|
-
class Unit <
|
2
|
+
class Unit < Structure
|
3
3
|
include Price
|
4
4
|
|
5
|
-
key :
|
6
|
-
key :description, String
|
7
|
-
key :quantity, Integer, :default => 1
|
8
|
-
|
9
|
-
validates_inclusion_of :condition, :in => 1..6
|
10
|
-
|
11
|
-
def new?
|
12
|
-
condition == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
def used?
|
16
|
-
!new?
|
17
|
-
end
|
5
|
+
key :quantity, Integer, :default => 1
|
18
6
|
end
|
19
7
|
end
|
data/lib/kosher/venue.rb
CHANGED
@@ -1,12 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Kosher
|
2
4
|
class Venue < Structure
|
3
|
-
|
4
|
-
|
5
|
+
DATA_PATH = File.expand_path("../../../data/venues.yml", __FILE__)
|
6
|
+
|
7
|
+
key :_id, Integer
|
8
|
+
key :country, String
|
9
|
+
key :name, String
|
10
|
+
|
11
|
+
class << self
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
def all
|
15
|
+
@all ||= YAML.load_file(DATA_PATH).map do |hsh|
|
16
|
+
hsh['_id'] ||= hsh.delete('id')
|
17
|
+
new(hsh)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def amazon
|
22
|
+
@amazons ||= find_all { |e| e.name.include? 'Amazon' }
|
23
|
+
end
|
5
24
|
|
6
|
-
|
25
|
+
def each(&block)
|
26
|
+
all.each { |item| block.call(item) }
|
27
|
+
end
|
7
28
|
|
8
|
-
|
9
|
-
|
29
|
+
def find(id)
|
30
|
+
super() { |item| item._id == id }
|
31
|
+
end
|
10
32
|
end
|
11
33
|
end
|
12
34
|
end
|
data/lib/kosher/version.rb
CHANGED
data/lib/kosher.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
require 'active_model'
|
2
|
-
require 'certainty'
|
3
|
-
require 'money'
|
4
2
|
require 'structure'
|
5
3
|
|
4
|
+
module Kosher
|
5
|
+
class NotValid < StandardError
|
6
|
+
def initialize(record)
|
7
|
+
super(record.errors.full_messages.join(', '))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Structure
|
13
|
+
include ActiveModel::Validations
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def validate!
|
18
|
+
raise NotValid.new(self) unless valid?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
require 'kosher/offer'
|
data/test/kosher_test.rb
CHANGED
@@ -16,8 +16,9 @@ class TestKosher < MiniTest::Unit::TestCase
|
|
16
16
|
:currency => 'EUR')
|
17
17
|
assert_equal '10,00 €', unit.price.format
|
18
18
|
|
19
|
-
shipping = Shipping.new(:
|
20
|
-
:
|
19
|
+
shipping = Shipping.new(:available => true,
|
20
|
+
:cents => '300',
|
21
|
+
:currency => 'EUR')
|
21
22
|
assert_equal '3,00 €', shipping.price.format
|
22
23
|
|
23
24
|
offer = Offer.new(:shipping => shipping,
|
@@ -34,30 +35,35 @@ class TestKosher < MiniTest::Unit::TestCase
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def test_validation
|
37
|
-
assert_raises(
|
38
|
-
|
39
|
-
|
40
|
-
:currency => 'USD')
|
41
|
-
assert unit.kosher?
|
38
|
+
assert_raises(NotValid) { Detail.new.kosher? }
|
39
|
+
detail = Detail.new(:condition => 1)
|
40
|
+
assert detail.kosher?
|
42
41
|
|
43
|
-
assert_raises(
|
42
|
+
assert_raises(NotValid) { Shipping.new.kosher? }
|
44
43
|
shipping = Shipping.new(:available => true,
|
45
44
|
:cents => 100,
|
46
45
|
:currency => 'USD')
|
47
46
|
assert shipping.kosher?
|
48
47
|
|
49
|
-
assert_raises(
|
48
|
+
assert_raises(NotValid) { Seller.new.kosher? }
|
50
49
|
seller = Seller.new(:name => 'John Doe')
|
51
50
|
assert seller.kosher?
|
52
51
|
|
53
|
-
assert_raises(
|
54
|
-
offer = Offer.new(:
|
52
|
+
assert_raises(NotValid) { Offer.new.kosher? }
|
53
|
+
offer = Offer.new(:detail => detail,
|
55
54
|
:shipping => shipping,
|
56
55
|
:seller => seller,
|
56
|
+
:unit => Unit.new,
|
57
57
|
:venue_id => 1)
|
58
58
|
assert offer.kosher?
|
59
59
|
end
|
60
60
|
|
61
|
+
def test_venues
|
62
|
+
assert_kind_of Venue, Venue.first
|
63
|
+
assert 'Amazon.com', Venue.find(1).name
|
64
|
+
assert_nil Venue.find(0)
|
65
|
+
end
|
66
|
+
|
61
67
|
def test_amazon_venues
|
62
68
|
assert_equal 8, Venue.amazon.size
|
63
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kosher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70322729328200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70322729328200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: certainty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70322729327560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70322729327560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: money
|
38
|
-
requirement: &
|
38
|
+
requirement: &70322729326860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,18 +43,18 @@ dependencies:
|
|
43
43
|
version: '3.7'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70322729326860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: structure
|
49
|
-
requirement: &
|
49
|
+
requirement: &70322729326360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.19'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70322729326360
|
58
58
|
description: Online selling, abstracted
|
59
59
|
email: code@papercavalier.com
|
60
60
|
executables: []
|
@@ -70,7 +70,8 @@ files:
|
|
70
70
|
- data/venues.yml
|
71
71
|
- kosher.gemspec
|
72
72
|
- lib/kosher.rb
|
73
|
-
- lib/kosher/
|
73
|
+
- lib/kosher/detail.rb
|
74
|
+
- lib/kosher/filter.rb
|
74
75
|
- lib/kosher/offer.rb
|
75
76
|
- lib/kosher/price.rb
|
76
77
|
- lib/kosher/seller.rb
|
@@ -93,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
94
|
version: '0'
|
94
95
|
segments:
|
95
96
|
- 0
|
96
|
-
hash: -
|
97
|
+
hash: -2784991868490813803
|
97
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
99
|
none: false
|
99
100
|
requirements:
|
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
103
|
version: '0'
|
103
104
|
segments:
|
104
105
|
- 0
|
105
|
-
hash: -
|
106
|
+
hash: -2784991868490813803
|
106
107
|
requirements: []
|
107
108
|
rubyforge_project:
|
108
109
|
rubygems_version: 1.8.6
|
data/lib/kosher/base.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Kosher
|
2
|
-
class Base < Structure
|
3
|
-
include ActiveModel::Validations
|
4
|
-
|
5
|
-
def self.inherited(child)
|
6
|
-
child.key :foo
|
7
|
-
child.key :kosher, Boolean, :default => true
|
8
|
-
end
|
9
|
-
|
10
|
-
def kosher?
|
11
|
-
unless valid?
|
12
|
-
raise StandardError.new(errors.full_messages.join(', '))
|
13
|
-
end
|
14
|
-
|
15
|
-
kosher
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|