dandy 0.10.0 → 0.11.0

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: f200ac79d319f41022b6dbc1bbcaa1657a96a092
4
- data.tar.gz: 1eee9c46e08a02edea020dd83e34634363cdd6ed
3
+ metadata.gz: 44208350faa4b49a2b907fb4894e37763c50f2cc
4
+ data.tar.gz: a39b0f9a8990f40a4f04b65c49f3c9377d4445d2
5
5
  SHA512:
6
- metadata.gz: 3d9081931b3bd4ae5e1efa3e7a3474d7e07d6055077f4e5785775fb2773c3377485c6d42f989c206da698cc2779d08689baf12171f0090d77bfc102471603ea8
7
- data.tar.gz: e4e59de3570dfceba866f133a62eb195e537612650599dcc916e02e4a9f21ab0b9aa4837f0962682c697f56e78e8f3df75843ae1192caf81d87cae8d67020eec
6
+ metadata.gz: 6ae6c24615f86775e5ab079c846225ccc40b3633d0ca4105bb1b94145641770998688cf8bf3f8e7300ece8b00cd0a161b9e808c0a12346fe1e90068a5c707c47
7
+ data.tar.gz: 0315435cf5dd9ba67e9726b7cd5ab351fbbbd83e9e16ace5870aa503d3021020745124b57eda8fe2be4b0c25dbf477c05b15c7e7ab6933ddd3688d05cd954c3d
data/lib/dandy/chain.rb CHANGED
@@ -69,8 +69,19 @@ module Dandy
69
69
  end
70
70
 
71
71
  def run_command(command)
72
- action = @container.resolve(command.name.to_sym)
73
- result = action.call
72
+ if command.entity?
73
+ entity = @container.resolve(command.entity_name.to_sym)
74
+ method_name = command.entity_method.to_sym
75
+
76
+ param_names = entity.class.instance_method(method_name).parameters.map(&:last)
77
+ params = param_names.map {|param_name| @container.resolve(param_name)}
78
+
79
+ result = entity.public_send(method_name, *params)
80
+ else
81
+ action = @container.resolve(command.name.to_sym)
82
+ result = action.call
83
+ end
84
+
74
85
 
75
86
  @container
76
87
  .register_instance(result, command.result_name.to_sym)
@@ -1,6 +1,6 @@
1
1
  module Syntax
2
2
  class Command < Treetop::Runtime::SyntaxNode
3
- attr_reader :name, :result_name
3
+ attr_reader :name, :result_name, :entity_method, :entity_name
4
4
 
5
5
  def parse
6
6
  @is_async = text_value.start_with? '=*'
@@ -18,6 +18,12 @@ module Syntax
18
18
  @name = full_name
19
19
  end
20
20
 
21
+ if full_name.include? '.'
22
+ parts = full_name.split('.')
23
+ @entity_name = parts[0]
24
+ @entity_method = parts[1]
25
+ end
26
+
21
27
  self
22
28
  end
23
29
 
@@ -32,5 +38,9 @@ module Syntax
32
38
  def sequential?
33
39
  @is_sequential
34
40
  end
41
+
42
+ def entity?
43
+ @entity_name && @entity_method
44
+ end
35
45
  end
36
46
  end
@@ -0,0 +1,4 @@
1
+ module Syntax
2
+ class EntityMethod < Treetop::Runtime::SyntaxNode
3
+ end
4
+ end
@@ -7,6 +7,7 @@ require_relative 'syntax/primitives/http_status'
7
7
  require_relative 'syntax/primitives/parameter'
8
8
  require_relative 'syntax/primitives/path'
9
9
  require_relative 'syntax/primitives/result_name'
10
+ require_relative 'syntax/primitives/entity_method'
10
11
 
11
12
  require_relative 'syntax/action'
12
13
  require_relative 'syntax/actions'
@@ -40,13 +40,17 @@ grammar Syntax
40
40
  end
41
41
 
42
42
  rule command
43
- (arrow result_name [a-z0-9_\/]+) 1..1 <Command>
43
+ (arrow result_name [a-z0-9_\/]+ entity_method) 1..1 <Command>
44
44
  end
45
45
 
46
46
  rule result_name
47
47
  ([a-z0-9_]+ '@') 0..1 <ResultName>
48
48
  end
49
49
 
50
+ rule entity_method
51
+ ('.' [a-z0-9_]+ ) 0..1 <EntityMethod>
52
+ end
53
+
50
54
  rule commands
51
55
  command* <Commands>
52
56
  end
data/lib/dandy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dandy
2
- VERSION = '0.10.0'.freeze
2
+ VERSION = '0.11.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dandy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hypo
@@ -273,6 +273,7 @@ files:
273
273
  - lib/dandy/routing/syntax/nodes.rb
274
274
  - lib/dandy/routing/syntax/primitives/arrow.rb
275
275
  - lib/dandy/routing/syntax/primitives/back_arrow.rb
276
+ - lib/dandy/routing/syntax/primitives/entity_method.rb
276
277
  - lib/dandy/routing/syntax/primitives/eol.rb
277
278
  - lib/dandy/routing/syntax/primitives/http_status.rb
278
279
  - lib/dandy/routing/syntax/primitives/http_verb.rb