unparser 0.5.1 → 0.5.2

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
  SHA256:
3
- metadata.gz: 5edf8f2731473b62649c92936d8c04ff8a19e598bdc9811feb332d8cd3cff58f
4
- data.tar.gz: 8e47978900270932616a7c7b1a8869442d0d0e64c90a6147b7bd6d0938edea44
3
+ metadata.gz: 87327818d4054325cbf2017759e01a434fd80242e6319747ea97326770752e35
4
+ data.tar.gz: 8832d57dfb3f1a4e5755ad5c6737cea20ee4302a2b67d6ff2bb7a0a6cc71dc74
5
5
  SHA512:
6
- metadata.gz: d5966f2f944ee5f596a3919d9c6d6b1ce1406ba4ab015b39d220941f35c4c5e5aeb401c270dab0b60883bd8b5fb3379d7dafe28be657a4af9fa4045be784a6f4
7
- data.tar.gz: 837b201d4d4ea307cbdc50d04640957618f6ccec1e7d5782b5b3654901369d80f02425d5c4a9b61cb1f90fb87d14146fff4889b7b1d49039369d58fdc33aa7d8
6
+ metadata.gz: e3e889b7a0130dbe3a77c32ae8d38cc0260b39b2785fba78e8f9033e29f1364699564dc6e2269b0c6a99a989d91f684a5dbbb78dc584c71b53ed05b102eaa9f7
7
+ data.tar.gz: d34a0f19d72855c962ceb9165d909133859ca38f055426b05b905266c9f9145655f1370219a70f2de1d04f2b4cd29cbd818c623b9a77a95385f70d457182ab02
@@ -50,6 +50,23 @@ module Unparser
50
50
  end.content
51
51
  end
52
52
 
53
+ # Unparse with validation
54
+ #
55
+ # @param [Parser::AST::Node, nil] node
56
+ # @param [Array] comment_array
57
+ #
58
+ # @return [Either<Validation,String>]
59
+ def self.unparse_validate(node, comment_array = [])
60
+ generated = unparse(node, comment_array)
61
+ validation = Validation.from_string(generated)
62
+
63
+ if validation.success?
64
+ MPrelude::Either::Right.new(generated)
65
+ else
66
+ MPrelude::Either::Left.new(validation)
67
+ end
68
+ end
69
+
53
70
  # Unparse capturing errors
54
71
  #
55
72
  # This is mostly useful for writing testing tools against unparser.
@@ -71,6 +71,27 @@ module Unparser
71
71
  )
72
72
  end
73
73
 
74
+ # Create validator from node
75
+ #
76
+ # @param [Parser::AST::Node] original_node
77
+ #
78
+ # @return [Validator]
79
+ def self.from_node(original_node)
80
+ generated_source = Unparser.unparse_either(original_node)
81
+
82
+ generated_node = generated_source
83
+ .lmap(&method(:const_unit))
84
+ .bind(&Unparser.public_method(:parse_either))
85
+
86
+ new(
87
+ identification: '(string)',
88
+ original_source: generated_source,
89
+ original_node: MPrelude::Either::Right.new(original_node),
90
+ generated_source: generated_source,
91
+ generated_node: generated_node
92
+ )
93
+ end
94
+
74
95
  # Create validator from file
75
96
  #
76
97
  # @param [Pathname] path
@@ -45,7 +45,7 @@ module Unparser
45
45
  def effective_writer_class
46
46
  if details.binary_syntax_allowed?
47
47
  Binary
48
- elsif details.selector_unary_operator?
48
+ elsif details.selector_unary_operator? && n_send?(node)
49
49
  Unary
50
50
  elsif write_as_attribute_assignment?
51
51
  AttributeAssignment
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abstract_type