dsl_maker 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a60b85736172ba9bfbd06b14f39a8d0163bd6cf1
4
- data.tar.gz: 32d6433a84322447e8104e921c9a47e354a60f11
3
+ metadata.gz: 2f42b67736e6299fee74ad059d995f9f0e9e71dc
4
+ data.tar.gz: cc54596f31ec4278eb33c5a11d504b1774556634
5
5
  SHA512:
6
- metadata.gz: e99238cb102708130d8ea95967c5acf0764988b9db5123e395f67a9f3213c8cdff94e7807d835884d6e9efb07af931a708bd69fdc9c3d66ae5e384a8543a62cb
7
- data.tar.gz: 233cd1b86c6a0cee61a04ade5f947aa2b78ee35a69d14750bf4fb020f3137d5d8854548110d6483650ee9cb4d570f61be4b1999764fe6a84b0888e45f1bb0d43
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.6 Aug ?? 2015
4
- - Added add_verification(name?) to allow for runtime verifications
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 add_coercion() to allow the user to define new coercions for use when
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.
@@ -1,6 +1,6 @@
1
1
  module DSL
2
2
  class Maker
3
3
  # The current version of this library
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
6
6
  end
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.6
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-03 00:00:00.000000000 Z
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile