dsl_maker 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes +8 -4
- data/README.md +80 -3
- data/lib/dsl/maker/version.rb +1 -1
- data/lib/dsl/maker.rb +7 -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: 2f42b67736e6299fee74ad059d995f9f0e9e71dc
|
4
|
+
data.tar.gz: cc54596f31ec4278eb33c5a11d504b1774556634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffe540380885b22fd3dc7a7d118ada0ae1ac958502619cbbea19f2c42b2546ccd60e9147a3475dc58d83c2b69982c87f08a7e6251ea172b141b7bf5bcda6e007
|
7
|
+
data.tar.gz: a0950aa163fe8b9c8b41b311c85ee369c229bd32099f6ce742a2e7f62f3b954effefcbfc7a90777287dc67ea84a482951dd5672a567cfb3d3ae10ad845dc6556
|
data/Changes
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
Revision history for DSL::Maker (ordered by revision number).
|
2
2
|
|
3
|
-
0.0.
|
4
|
-
- Added
|
3
|
+
0.0.7 Aug 06 2015
|
4
|
+
- Added the 'Any' type coercion.
|
5
|
+
- Added a TL;DR section at the top of the README.
|
6
|
+
|
7
|
+
0.0.6 Aug 03 2015
|
8
|
+
- Added add_verification(name) to allow for runtime verifications
|
5
9
|
- Don't require a dummy block when passing a DSL class to add_entrypoint.
|
6
10
|
- Refactored several items into private methods
|
7
11
|
- Pulled the provided types and helpers out of the class definition
|
8
12
|
|
9
13
|
0.0.5 Jul 30 2015
|
10
14
|
- Added missing YaRDOC for new features in 0.0.4
|
11
|
-
- Added
|
15
|
+
- Added add_type() to allow the user to define new type coercions for use when
|
12
16
|
creating their DSL.
|
13
|
-
- Eat our own dogfood vis-a-vis helpers and coercions.
|
17
|
+
- Eat our own dogfood vis-a-vis helpers and type coercions.
|
14
18
|
|
15
19
|
0.0.4 Jul 29 2015
|
16
20
|
- Added add_helper() to allow the user to define new helper methods for use
|
data/README.md
CHANGED
@@ -9,6 +9,83 @@
|
|
9
9
|
[![Code Coverage](https://img.shields.io/codecov/c/github/robkinyon/ruby-dsl-maker.svg)](https://codecov.io/github/robkinyon/ruby-dsl-maker)
|
10
10
|
[![Inline docs](http://inch-ci.org/github/robkinyon/ruby-dsl-maker.png)](http://inch-ci.org/github/robkinyon/ruby-dsl-maker)
|
11
11
|
|
12
|
+
## TL;DR
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'dsl/maker'
|
16
|
+
|
17
|
+
Car = Struct.new(:maker, :engine)
|
18
|
+
Engine = Struct.new(:is_hemi)
|
19
|
+
Truck = Struct.new(:maker, :engine, :towing)
|
20
|
+
|
21
|
+
class Vehicle::DSL < DSL::Maker
|
22
|
+
dsl_engine = generate_dsl({
|
23
|
+
:hemi => Boolean,
|
24
|
+
}) do
|
25
|
+
Engine.new(hemi)
|
26
|
+
end
|
27
|
+
|
28
|
+
add_entrypoint(:car, {
|
29
|
+
:maker => String,
|
30
|
+
:engine => dsl_engine,
|
31
|
+
}) do |*args|
|
32
|
+
default(maker, args, 0)
|
33
|
+
Car.new(maker, engine)
|
34
|
+
end
|
35
|
+
|
36
|
+
add_entrypoint(:truck, {
|
37
|
+
:maker => String,
|
38
|
+
:towing => Integer,
|
39
|
+
:engine => dsl_engine,
|
40
|
+
}) do |*args|
|
41
|
+
default(maker, args, 0)
|
42
|
+
Truck.new(maker, engine, towing)
|
43
|
+
end
|
44
|
+
|
45
|
+
add_verification(:car) do |item|
|
46
|
+
return "Cars need engines" unless item.engine
|
47
|
+
end
|
48
|
+
add_verification(:truck) do |item|
|
49
|
+
return "Trucks need engines" unless item.engine
|
50
|
+
return "Trucks aren't wimps" unless item.towing > 1000
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Then, use it as so:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
#!/usr/bin/env ruby
|
59
|
+
|
60
|
+
require ‘vehicle/dsl’
|
61
|
+
|
62
|
+
filename = ARGV.shift || raise “No filename provided.”
|
63
|
+
|
64
|
+
# This raises the error
|
65
|
+
vehicles = Vehicle::DSL.parse_dsl(
|
66
|
+
IO.read(filename),
|
67
|
+
)
|
68
|
+
```
|
69
|
+
|
70
|
+
with a file that could look like:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
car do
|
74
|
+
make 'Honda Civic'
|
75
|
+
engine {
|
76
|
+
hemi no
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
truck 'Ford F-150' do
|
81
|
+
engine {
|
82
|
+
hemi On
|
83
|
+
}
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
## Rationale
|
88
|
+
|
12
89
|
Writing single-level Ruby-like DSLs is really easy. Ruby practically builds them
|
13
90
|
for you with a little meta-programming. [Docile](https://github.com/ms-ati/docile)
|
14
91
|
makes it ridiculously easy and there are nearly a dozen other modules to do so.
|
@@ -327,6 +404,7 @@ were encountered.
|
|
327
404
|
|
328
405
|
There are four pre-defined type coercions for use within `generate_dsl()`:
|
329
406
|
|
407
|
+
* Any - This takes whatever you give it and returns it back.
|
330
408
|
* String - This takes whatever you give it and returns the string within it.
|
331
409
|
* Integer - This takes whatever you give it and returns the integer within it.
|
332
410
|
* Boolean - This takes whatever you give it and returns the truthiness of it.
|
@@ -358,8 +436,6 @@ $ gem install dsl_maker
|
|
358
436
|
* Add support for auto-generating documentation
|
359
437
|
* Add default block that returns a Struct-of-Structs named after entrypoints
|
360
438
|
* Add example of binary to execute a DSL
|
361
|
-
* Add example of/link to validation and production of data structure
|
362
|
-
* 3-part DSL handling
|
363
439
|
* DSL for DSL construction
|
364
440
|
* Add "include" helper that loads another file and continues the execution
|
365
441
|
* Should provide useful directory searching
|
@@ -376,10 +452,11 @@ Works on [all ruby versions since 1.9.3](https://github.com/robkinyon/ruby-dsl-m
|
|
376
452
|
|
377
453
|
## Note on Patches/Pull Requests
|
378
454
|
|
379
|
-
* Fork the project.
|
455
|
+
* Fork the project on GitHub.
|
380
456
|
* Setup your development environment with:
|
381
457
|
`gem install bundler; bundle install`
|
382
458
|
* Make your feature addition or bug fix in a branch.
|
459
|
+
* I will only accept PRs from branches, never master.
|
383
460
|
* Add tests for it. This is important so I don't break it in a future version
|
384
461
|
unintentionally. Plus, I maintain 100% code coverage.
|
385
462
|
* Commit.
|
data/lib/dsl/maker/version.rb
CHANGED
data/lib/dsl/maker.rb
CHANGED
@@ -13,6 +13,9 @@ class DSL::Maker
|
|
13
13
|
alias :___get :instance_variable_get
|
14
14
|
end
|
15
15
|
|
16
|
+
# Create the DSL::Maker::Any type identifier
|
17
|
+
Any = nil
|
18
|
+
|
16
19
|
# This is a useful module that contains all the Boolean handling we need.
|
17
20
|
module Boolean
|
18
21
|
{
|
@@ -320,6 +323,10 @@ end
|
|
320
323
|
|
321
324
|
# These are the default setups.
|
322
325
|
|
326
|
+
DSL::Maker.add_type(DSL::Maker::Any) do |attr, *args|
|
327
|
+
___set(attr, args[0]) unless args.empty?
|
328
|
+
___get(attr)
|
329
|
+
end
|
323
330
|
DSL::Maker.add_type(Integer) do |attr, *args|
|
324
331
|
___set(attr, args[0].to_i) unless args.empty?
|
325
332
|
___get(attr)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsl_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Kinyon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docile
|