bottle_service 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -46
- data/lib/bottle_service/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b2177887de0a1595cafa42aac62df1f25c45922
|
4
|
+
data.tar.gz: ee6c78025b10ff84e0440fd2b8ea8fcb30eac5ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d0620fbc90a43db67c5f5958f9c41a4211d5b42aafacd00da75261a939dbb6b0321fc3b865339f67a8643bcc1f3087025d57110d33b821b9e96bbba1aac9a1
|
7
|
+
data.tar.gz: b23d27b35118227c1704182f04cd7677a0e081450d3441bfe08650a89fd73e408e4bd042f963d8bdcfcec1ddb29f6c877a978fda612b43e867032124e4700b62
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### BottleService
|
2
2
|
|
3
|
-
|
3
|
+
#### Installation
|
4
4
|
|
5
5
|
``` terminal
|
6
6
|
$ gem install bottle_service
|
@@ -12,12 +12,12 @@ or in your **Gemfile**
|
|
12
12
|
gem "bottle_service"
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
#### Usage
|
16
16
|
|
17
|
-
|
17
|
+
##### Simple example
|
18
18
|
|
19
19
|
``` ruby
|
20
|
-
class Greeter < BottleService
|
20
|
+
class Greeter < BottleService::Waitress
|
21
21
|
attribute :name, String
|
22
22
|
|
23
23
|
def call
|
@@ -29,45 +29,3 @@ Greeter.call name: "Space" # Hello Space!
|
|
29
29
|
# or
|
30
30
|
Greeter.(name: "Space") # Hello Space!
|
31
31
|
```
|
32
|
-
|
33
|
-
#### Extended example
|
34
|
-
|
35
|
-
``` ruby
|
36
|
-
class CreateProduct < BottleService
|
37
|
-
attribute :shop, Shop
|
38
|
-
attribute :name, String
|
39
|
-
attribute :price_cents, Integer
|
40
|
-
attribute :tax_percentage, Float
|
41
|
-
attribute :tags, Array[Tag]
|
42
|
-
|
43
|
-
def call
|
44
|
-
product = @shop.products.create name: @name,
|
45
|
-
price_cents: @price_cents,
|
46
|
-
tax_cents: calculate_tax
|
47
|
-
|
48
|
-
raise BottleServiceError, "Failed to save product" unless product.persisted?
|
49
|
-
|
50
|
-
add_tags_to_product(product)
|
51
|
-
|
52
|
-
product
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def calculate_tax
|
58
|
-
@price_cents / (1 + (@tax_percentage / 100))
|
59
|
-
end
|
60
|
-
|
61
|
-
def add_tags_to_product(product)
|
62
|
-
@tags.each do |tag|
|
63
|
-
product.append tag
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
CreateProduct.call shop: current_shop,
|
69
|
-
name: "Awesome T-Shirt",
|
70
|
-
price: 2000,
|
71
|
-
tax: 21.0,
|
72
|
-
tags: tags
|
73
|
-
```
|