icecream 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 992459f1f7e6f8d5a07c30f4863d1518e4a9d2dd
4
- data.tar.gz: ed1ef3476a13c126ecf684468462cf1503993028
3
+ metadata.gz: 34ed85459ee26a0ae8f61298e8a406c8a68b7c86
4
+ data.tar.gz: dcb254332f4362c31006254f95d24c19a0b10c07
5
5
  SHA512:
6
- metadata.gz: 3610d29bef925ae506ceb16ce132a247633bf8a211d0ecec6a5dce59196338acc8b4318175e6ce36b7fbac1b395a2831b0d85acd77ac12c05fcb7121d5dd05e8
7
- data.tar.gz: cc33b45a9549cd769cc8439653d794a8099f1da543106d4e1bd28109408c52e2076bf1fdc2d19f3f1db2b979045b83bbfa3aa25921b59ab2b53a1dd87b56d827
6
+ metadata.gz: 3e4c82d5ea344431394d13c91c84bd3f7459f5d7ba9aeb6ee74e4b914430867f9da8b397db36e8270ba5e0a48cc5d2245fc2c58385f7088b649ce5137cf8db1f
7
+ data.tar.gz: 4e916af70805783fe9bceb48a73e6403dd24e5e4646ce8fb5727018362a3c87af0b8506d22c4489097acdc1f275f1578914565cdcd0f2e8d5c6ca277ab4f2d5c
data/README.md CHANGED
@@ -8,30 +8,29 @@ IceCream
8
8
  [![Coverage Status](https://coveralls.io/repos/camiloribeiro/icecream/badge.png)](https://coveralls.io/r/camiloribeiro/icecream)
9
9
  [![endorse](https://api.coderwall.com/camiloribeiro/endorsecount.png)](https://coderwall.com/camiloribeiro)
10
10
 
11
- I was looking for a really simple factory gem, such as factory_grill, but without any magic to use with rails. I was incompetent at that, so I built this really simple Factory called IceCream.
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
- It is a IceCream factory. It means that you can fabricate any IceCream flavor that you have in your fridge :D And, as any Factory, you can change the properties of an object that you got from the fridge.
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 is going to create a class (with the file name) and fill this class with instance variables for each one of the variables, and, of course set the value for the variables :)
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
- collor = :brown
23
+ colour = :brown
25
24
  calories = 150
26
25
  price = 15.5
27
26
 
28
- At the end, you can call the IceCream factory using the following commands:
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
- And it is going to work in your non-rails as good as in your rails projects :D It is just ruby code, there is not one single dependency (so far).
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, pull request, thank you :)
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
 
@@ -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
- instance_variable_set("@"+instance_name, flavor)
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
@@ -1,3 +1,3 @@
1
1
  module IceCream
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -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.9
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-27 00:00:00.000000000 Z
11
+ date: 2013-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry