dsl_maker 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43ac58c18299e11f3a0d0a5153b091099abd4ad4
4
- data.tar.gz: 2d581831a64b7897260837b43ab095890a655bc0
3
+ metadata.gz: 85f97d8d73eceeca3b40c4ad156e69b236ffa5f5
4
+ data.tar.gz: 603975a69ba6f163e24928aac73ef12c5cdfcb1a
5
5
  SHA512:
6
- metadata.gz: da69b4dfdd4603a15cf4e95c64e41cfdfa7589d86bd8d7b6d53df157a1dc16906dfaa7d992792f5f586edac8097779aa5b085f246516e7350047b949ff1dc12a
7
- data.tar.gz: d6a063cabdc29e419e856c2aade33afcd5fbf88a789303789ec654e4a015aca85473cd3c2d16a34022c369260adacb4e997412f4a0a8baf10af6c56d78d50509
6
+ metadata.gz: 37fd0149a8290377dbc7033b5ffa0fcd9b5c771c5649120c9c1746c4b063f757c8b3b00e5e2383f5fcb3442276035feac06ab82c87e95eb793ea37a3a9c56d7d
7
+ data.tar.gz: 129b55c93089a927e022904d9683c050f9da2351eabd8654ccef2d81b969e23247d1dacba920e84a45a4bf86815fb65cf472071a18c17ede686120b32c55e0ac
@@ -2,20 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - ruby-head
5
+ - 2.4
5
6
  - 2.3
6
7
  - 2.2
7
8
  - 2.1
8
9
  - 2.0.0
9
10
  - 1.9.3
10
- - rbx-2
11
- matrix:
12
- include:
13
- - rvm: jruby-head
14
- env: JRUBY_OPTS="$JRUBY_OPTS -Xcli.debug=true --debug" # for simplecov
15
- - rvm: jruby-21mode
16
- env: JRUBY_OPTS="$JRUBY_OPTS -Xcli.debug=true --debug" # for simplecov
17
- - rvm: jruby-20mode
18
- env: JRUBY_OPTS="$JRUBY_OPTS -Xcli.debug=true --debug" # for simplecov
19
- - rvm: jruby-19mode
20
- env: JRUBY_OPTS="$JRUBY_OPTS -Xcli.debug=true --debug" # for simplecov
21
- fast_finish: true
data/Changes CHANGED
@@ -1,5 +1,8 @@
1
1
  Revision history for DSL::Maker (ordered by revision number).
2
2
 
3
+ 1.0.1 Nov 25 2018
4
+ - Add support for Hash
5
+
3
6
  1.0.0 Aug 24 2018
4
7
  - The license has changed from GPLv2 to MIT
5
8
  - This is a breaking change, hence the increment to 1.0.0
data/README.md CHANGED
@@ -57,9 +57,9 @@ Then, use it as so:
57
57
  ```ruby
58
58
  #!/usr/bin/env ruby
59
59
 
60
- require vehicle/dsl
60
+ require 'vehicle/dsl'
61
61
 
62
- filename = ARGV.shift || raise No filename provided.”
62
+ filename = ARGV.shift || raise 'No filename provided.'
63
63
 
64
64
  # This raises the error
65
65
  vehicles = Vehicle::DSL.parse_dsl(
@@ -408,13 +408,14 @@ encountered.
408
408
 
409
409
  ### Type Coercions
410
410
 
411
- There are four pre-defined standard type coercions available for `generate_dsl()`:
411
+ There are five pre-defined standard type coercions available for `generate_dsl()`:
412
412
 
413
413
  Standard coercions:
414
414
  * Any - This takes whatever you give it and returns it back.
415
415
  * String - This takes whatever you give it and returns the string within it.
416
416
  * Integer - This takes whatever you give it and returns the integer within it.
417
417
  * Boolean - This takes whatever you give it and returns the truthiness of it.
418
+ * Hash - This takes a block and returns a Hash of the method calls.
418
419
 
419
420
  You can add additional standard type coercions using `add_type()` as described
420
421
  above.
@@ -97,6 +97,20 @@ class DSL::Maker
97
97
  type.instance_of? ArrayType
98
98
  end
99
99
 
100
+ class HashType
101
+ def initialize(rv)
102
+ @rv = rv
103
+ end
104
+
105
+ def respond_to_missing?(*args)
106
+ true
107
+ end
108
+
109
+ def method_missing(methname, *args)
110
+ @rv[methname.to_s] = args[0] unless methname.to_s =~ /__.*__/
111
+ end
112
+ end
113
+
100
114
  # Parse the DSL provided in the parameter.
101
115
  #
102
116
  # @param dsl [String] The DSL to be parsed by this class.
@@ -350,6 +364,28 @@ class DSL::Maker
350
364
  instance_exec('@' + name.to_s, *args, &@@types[type])
351
365
  end
352
366
  end
367
+ elsif is_hash?(type)
368
+ as_attr = '@' + name.to_s
369
+
370
+ klass.class_eval do
371
+ define_method(name.to_sym) do |*args, &dsl_block|
372
+ if (!args.empty? || dsl_block)
373
+ rv = {}
374
+ Docile.dsl_eval(HashType.new(rv), &dsl_block) if dsl_block
375
+
376
+ # This is the one place where we pull out the entrypoint results and
377
+ # put them into the control class.
378
+ if klass.parent_class
379
+ # Use the full instance_variable_get() in order to avoid having to
380
+ # create accessors that could be misused outside this class.
381
+ klass.parent_class.instance_variable_get(:@accumulator).push(rv)
382
+ end
383
+
384
+ ___set(as_attr, rv)
385
+ end
386
+ ___get(as_attr)
387
+ end
388
+ end
353
389
  elsif is_dsl?(type)
354
390
  as_attr = '@' + name.to_s
355
391
  klass.class_eval do
@@ -426,9 +462,9 @@ class DSL::Maker
426
462
  end
427
463
 
428
464
  def self.run_dsl()
429
- # build_dsl_element() will use @accumulator to handle multiple entrypoints if
430
- # the class in question is a root DSL class. Reset it here so that we're only
431
- # handling the values from this run.
465
+ # build_dsl_element() will use @accumulator to handle multiple entrypoints
466
+ # if the class in question is a root DSL class. Reset it here so that we're
467
+ # only handling the values from this run.
432
468
  @accumulator = []
433
469
 
434
470
  yield
@@ -436,6 +472,10 @@ class DSL::Maker
436
472
  return @accumulator
437
473
  end
438
474
 
475
+ def self.is_hash?(proto)
476
+ proto == Hash
477
+ end
478
+
439
479
  def self.is_dsl?(proto)
440
480
  proto.is_a?(Class) && proto.ancestors.include?(DSL::Maker::Base)
441
481
  end
@@ -1,6 +1,6 @@
1
1
  module DSL
2
2
  class Maker
3
3
  # The current version of this library
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
6
6
  end
@@ -44,6 +44,8 @@ module Structs
44
44
 
45
45
  Color = Struct.new(:name)
46
46
  Fruit = Struct.new(:name, :color)
47
+
48
+ Taggable = Struct.new(:name, :tags)
47
49
  end
48
50
 
49
51
  $:.push 'spec/lib'
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kinyon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-19 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile