icecream 0.0.9 → 0.0.10
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 +4 -4
- data/README.md +16 -11
- data/lib/icecream/icecream.rb +21 -8
- data/lib/icecream/version.rb +1 -1
- data/spec/icecream_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34ed85459ee26a0ae8f61298e8a406c8a68b7c86
|
4
|
+
data.tar.gz: dcb254332f4362c31006254f95d24c19a0b10c07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e4c82d5ea344431394d13c91c84bd3f7459f5d7ba9aeb6ee74e4b914430867f9da8b397db36e8270ba5e0a48cc5d2245fc2c58385f7088b649ce5137cf8db1f
|
7
|
+
data.tar.gz: 4e916af70805783fe9bceb48a73e6403dd24e5e4646ce8fb5727018362a3c87af0b8506d22c4489097acdc1f275f1578914565cdcd0f2e8d5c6ca277ab4f2d5c
|
data/README.md
CHANGED
@@ -8,30 +8,29 @@ IceCream
|
|
8
8
|
[](https://coveralls.io/r/camiloribeiro/icecream)
|
9
9
|
[](https://coderwall.com/camiloribeiro)
|
10
10
|
|
11
|
-
I was looking for a really simple factory gem, such as
|
11
|
+
I was looking for a really simple factory gem, such as factory_girl, but without any magic to use with rails. I was incompetent at that, so I built this really simple factory called IceCream.
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
The idea
|
13
|
+
The Idea
|
16
14
|
-------
|
15
|
+
|
17
16
|
The central idea is to have a very simple file to describe what you want to fabricate. When I say simple, I mean SIMPLE. The file is just a "file.flavor" (plain text) with two collums: variable and default value.
|
18
17
|
|
19
|
-
This gem goes to the factory directory and for each ".flavor" file, it
|
18
|
+
This gem goes to the factory directory and for each ".flavor" file, it creates a class (with the given file name) and fills this class with instance variables for each one of the values declared.
|
20
19
|
|
21
|
-
Imagine a file called chocolate.flavor that has the following content
|
20
|
+
Imagine a file called chocolate.flavor that has the following content:
|
22
21
|
|
23
22
|
name = "Chocolate"
|
24
|
-
|
23
|
+
colour = :brown
|
25
24
|
calories = 150
|
26
25
|
price = 15.5
|
27
26
|
|
28
|
-
|
27
|
+
After that, you can call the IceCream factory using the following commands:
|
29
28
|
|
30
29
|
$ IceCream.flavor :chocolate
|
31
30
|
|
32
31
|
and it is going to return a Chocolate (class) object called chocolate, with a string, a symbol, a float and an integer. Easy ;)
|
33
32
|
|
34
|
-
|
33
|
+
It works in your non-Rails Ruby project as well. It's just Ruby code, and there is not a single dependency (so far).
|
35
34
|
|
36
35
|
Installing
|
37
36
|
------------------
|
@@ -47,6 +46,8 @@ Gemfile
|
|
47
46
|
Using
|
48
47
|
---------
|
49
48
|
|
49
|
+
You can have different folders (fridges) with different factories definitions as exemplified bellow:
|
50
|
+
|
50
51
|
$ require 'icecream'
|
51
52
|
$ creamy_flavors = IceCream::Icecream.new "/path/to/flavors"
|
52
53
|
$ cheap_chocolate = creamy_flavors.flavor :chocolate
|
@@ -55,17 +56,21 @@ Using
|
|
55
56
|
$ diet_flavors = IceCream::Icecream.new "/path/to/Diet/flavors"
|
56
57
|
$ zero_sugar_chocolate = diet_flavors.flavor :chocolate
|
57
58
|
|
59
|
+
You can also, define an object from nowhere, creating it with a single line!
|
60
|
+
|
61
|
+
$ IceCream::IceCream.flavor :Orange, "[name = 'orange', color = :orange, price = 35.5, calories = 3]"
|
62
|
+
|
58
63
|
Have fun!
|
59
64
|
|
60
65
|
Contributing
|
61
66
|
--------------
|
62
67
|
|
63
|
-
Fork
|
68
|
+
Fork and send pull requests, as usual. Thank you! :)
|
64
69
|
|
65
70
|
LICENCE
|
66
71
|
-------------
|
67
72
|
|
68
|
-
Copyright 2013 Camilo Ribeiro camilo@camiloribeiro.com
|
73
|
+
Copyright 2013 Camilo Ribeiro <camilo@camiloribeiro.com>
|
69
74
|
|
70
75
|
This file is part of IceCream.
|
71
76
|
|
data/lib/icecream/icecream.rb
CHANGED
@@ -3,18 +3,31 @@ require File.join(File.dirname(__FILE__),"./parser")
|
|
3
3
|
module IceCream
|
4
4
|
class IceCream
|
5
5
|
|
6
|
+
def self.flavor flavor_name, flavor_details
|
7
|
+
object = Parser.objectify flavor_name.to_s, flavor_details
|
8
|
+
.gsub("[","")
|
9
|
+
.gsub("]","")
|
10
|
+
.split(",")
|
11
|
+
.map
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def self.create_instance instance_name, flavor, instance=nil
|
16
|
+
instance = self if instance.nil?
|
17
|
+
instance.instance_variable_set("@"+instance_name, flavor)
|
18
|
+
instance.define_singleton_method(instance_name) do
|
19
|
+
"@"+instance_name
|
20
|
+
end
|
21
|
+
instance.define_singleton_method(instance_name+"=") do |new_value|
|
22
|
+
"@"+instance_name = new_value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
6
26
|
def initialize(path)
|
7
27
|
Dir.glob("#{path}/*.flavor") do |flavor_file_path|
|
8
28
|
flavor = Parser.get_flavor flavor_file_path
|
9
29
|
instance_name = flavor.class.to_s.downcase
|
10
|
-
|
11
|
-
define_singleton_method(instance_name) do
|
12
|
-
"@"+instance_name
|
13
|
-
end
|
14
|
-
define_singleton_method(instance_name+"=") do |new_value|
|
15
|
-
require "pry"; binding.pry
|
16
|
-
"@"+instance_name = new_value
|
17
|
-
end
|
30
|
+
self.class.create_instance instance_name, flavor, self
|
18
31
|
end
|
19
32
|
|
20
33
|
def flavor flavor
|
data/lib/icecream/version.rb
CHANGED
data/spec/icecream_spec.rb
CHANGED
@@ -28,5 +28,13 @@ describe "Icecream" do
|
|
28
28
|
apple.price.should eq 1.5
|
29
29
|
apple.calories.should eq 1500
|
30
30
|
end
|
31
|
+
it "creates a new flavor from an array" do
|
32
|
+
new_flavor = IceCream::IceCream.flavor :Orange, "[name = 'orange', color = :orange, price = 35.5, calories = 3]"
|
33
|
+
new_flavor.class.should be Orange
|
34
|
+
new_flavor.name.should eq "orange"
|
35
|
+
new_flavor.color.should eq :orange
|
36
|
+
new_flavor.price.should eq 35.5
|
37
|
+
new_flavor.calories.should eq 3
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icecream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Camilo Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|