docile 1.0.0 → 1.0.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.
Files changed (5) hide show
  1. data/Gemfile +2 -2
  2. data/README.md +47 -17
  3. data/docile.gemspec +2 -2
  4. data/lib/docile/version.rb +1 -1
  5. metadata +13 -7
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ gemspec
5
5
 
6
6
  # Explicitly require test gems for Travis CI, since we're excluding dev dependencies
7
7
  group :test do
8
- gem "rake", "~> 0.9.2"
9
- gem "rspec", "~> 2.11.0"
8
+ gem "rake", ">= 0.9.2"
9
+ gem "rspec", ">= 2.11.0"
10
10
  end
data/README.md CHANGED
@@ -11,43 +11,73 @@ Let's make our Ruby DSLs more docile...
11
11
  [![Build Status](https://travis-ci.org/ms-ati/docile.png)](https://travis-ci.org/ms-ati/docile)
12
12
  [![Dependency Status](https://gemnasium.com/ms-ati/docile.png)](https://gemnasium.com/ms-ati/docile)
13
13
 
14
- ## Usage
14
+ ## Basic Usage
15
15
 
16
- Let's treat an Array's methods as its own DSL:
16
+ Let's say that we want to make a DSL for modifying Array objects.
17
+ Wouldn't it be great if we could just treat the methods of Array as a DSL?
17
18
 
18
- ``` ruby
19
- Docile.dsl_eval([]) do
19
+ ```ruby
20
+ with_array([]) do
20
21
  push 1
21
22
  push 2
22
23
  pop
23
24
  push 3
24
25
  end
25
- #=> [1, 3]
26
+ # => [1, 3]
26
27
  ```
27
28
 
28
- Mutating (changing) the array is fine, but what you probably really want as your DSL is actually a [Builder Pattern][2].
29
-
30
- For example, if you have a PizzaBuilder class that can already build a Pizza:
31
-
29
+ No problem, just define the method `with_array` like this:
32
30
  ``` ruby
33
- @sauce_level = :extra
34
- pizza = PizzaBuilder.new.cheese.pepperoni.sauce(@sauce_level).build
35
- #=> #<Pizza:0x00001009dc398 @cheese=true, @pepperoni=true, @bacon=false, @sauce=:extra>
31
+ def with_array(arr=[], &block)
32
+ Docile.dsl_eval(arr, &block)
33
+ end
36
34
  ```
37
35
 
38
- Then you can use this same PizzaBuilder class as a DSL:
36
+ Easy!
39
37
 
40
- ``` ruby
38
+ ## Advanced Usage
39
+
40
+ Mutating (changing) an Array instance is fine, but what usually makes a good DSL is a [Builder Pattern][2].
41
+
42
+ For example, let's say you want a DSL to specify how you want to build a Pizza:
43
+ ```ruby
41
44
  @sauce_level = :extra
42
- pizza = Docile.dsl_eval(PizzaBuilder.new) do
45
+
46
+ pizza do
43
47
  cheese
44
48
  pepperoni
45
49
  sauce @sauce_level
46
- end.build
50
+ end
51
+ # => #<Pizza:0x00001009dc398 @cheese=true, @pepperoni=true, @bacon=false, @sauce=:extra>
52
+ ```
53
+
54
+ And let's say we have a PizzaBuilder, which builds a Pizza like this:
55
+ ```ruby
56
+ Pizza = Struct.new(:cheese, :pepperoni, :bacon, :sauce)
57
+
58
+ class PizzaBuilder
59
+ def cheese(v=true); @cheese = v; end
60
+ def pepperoni(v=true); @pepperoni = v; end
61
+ def bacon(v=true); @bacon = v; end
62
+ def sauce(v=nil); @sauce = v; end
63
+ def build
64
+ Pizza.new(!!@cheese, !!@pepperoni, !!@bacon, @sauce)
65
+ end
66
+ end
67
+
68
+ PizzaBuilder.new.cheese.pepperoni.sauce(:extra).build
47
69
  #=> #<Pizza:0x00001009dc398 @cheese=true, @pepperoni=true, @bacon=false, @sauce=:extra>
48
70
  ```
49
71
 
50
- It's just that easy!
72
+ Then implement your DSL like this:
73
+
74
+ ``` ruby
75
+ def pizza(&block)
76
+ Docile.dsl_eval(PizzaBuilder.new, &block).build
77
+ end
78
+ ```
79
+
80
+ It's just that easy!
51
81
 
52
82
  [2]: http://stackoverflow.com/questions/328496/when-would-you-use-the-builder-pattern "Builder Pattern"
53
83
 
data/docile.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # Running rspec tests from rake
22
- s.add_development_dependency "rake", "~> 0.9.2"
23
- s.add_development_dependency "rspec", "~> 2.11.0"
22
+ s.add_development_dependency "rake", ">= 0.9.2"
23
+ s.add_development_dependency "rspec", ">= 2.11.0"
24
24
 
25
25
  # Github flavored markdown in YARD documentation
26
26
  # http://blog.nikosd.com/2011/11/github-flavored-markdown-in-yard.html
@@ -1,3 +1,3 @@
1
1
  module Docile
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-29 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.9.2
22
22
  type: :development
@@ -24,7 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.9.2
30
30
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: 2.11.0
38
38
  type: :development
@@ -40,7 +40,7 @@ dependencies:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 2.11.0
46
46
  - !ruby/object:Gem::Dependency
@@ -124,15 +124,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  - - ! '>='
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -2020809152847392489
127
130
  required_rubygems_version: !ruby/object:Gem::Requirement
128
131
  none: false
129
132
  requirements:
130
133
  - - ! '>='
131
134
  - !ruby/object:Gem::Version
132
135
  version: '0'
136
+ segments:
137
+ - 0
138
+ hash: -2020809152847392489
133
139
  requirements: []
134
140
  rubyforge_project: docile
135
- rubygems_version: 1.8.21
141
+ rubygems_version: 1.8.24
136
142
  signing_key:
137
143
  specification_version: 3
138
144
  summary: Docile keeps your Ruby DSL's tame and well-behaved