psychgus 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  #--
5
5
  # This file is part of Psychgus.
6
- # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # Psychgus is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2019-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
11
 
@@ -27,54 +16,56 @@ module Psychgus
27
16
  class SuperSniffer
28
17
  ###
29
18
  # A container for the parent of a Psych::Nodes::Node.
30
- #
19
+ #
31
20
  # A parent is a Mapping, Sequence, or a Key (Scalar) of a Mapping.
32
- #
21
+ #
33
22
  # You can use the getters in this class in {Styler} to filter what to change.
34
- #
23
+ #
35
24
  # If a Node method has not been exposed, you can use {#node}:
36
25
  # if parent.node_of?(:scalar)
37
26
  # parent.value = 'FUBAR'
38
27
  # parent.node.value = 'FUBAR' # Same as above
39
- #
28
+ #
40
29
  # parent.fubar = true # NoMethodError
41
30
  # parent.node.fubar = true # Use some new Psych::Nodes::Node method not in this version
42
31
  # # of Psychgus or that is not exposed by Parent
43
32
  # end
44
- #
45
- # @author Jonathan Bradley Whited (@esotericpig)
33
+ #
34
+ # @author Jonathan Bradley Whited
46
35
  # @since 1.0.0
47
- #
36
+ #
48
37
  # @see SuperSniffer
49
38
  # @see SuperSniffer#start_parent SuperSniffer#start_parent
50
39
  # @see SuperSniffer#end_parent SuperSniffer#end_parent
51
40
  # @see Styler
52
41
  ###
53
- class Parent < Delegator
42
+ class Parent < SimpleDelegator
54
43
  # Calling the getter is fine; calling the setter is *not* and could cause weird results.
55
- #
44
+ #
56
45
  # @return [Integer] the next child's position
57
46
  attr_accessor :child_position
58
-
47
+
59
48
  # Calling the getter is fine; calling the setter is *not* and could cause weird results.
60
- #
49
+ #
61
50
  # @return [nil,:key,:value] the next child's Mapping type, if {#node} is a Mapping
62
51
  attr_accessor :child_type
63
-
52
+
64
53
  # @return [:noface,Symbol,String] a tag (class name, value) for debugging; also used in {#to_s}
65
54
  attr_reader :debug_tag
66
-
55
+
67
56
  attr_reader :level # @return [Integer] the level of this Node in the YAML
68
57
  attr_reader :node # @return [Psych::Nodes::Node] the Node of this parent
69
58
  attr_reader :position # @return [Integer] the position of this Node in the YAML
70
-
59
+
71
60
  # Initialize this class with parent data.
72
- #
61
+ #
73
62
  # @param sniffer [SuperSniffer] the sniffer that contains this parent (not stored; used for data)
74
63
  # @param node [Psych::Nodes::Node] the node of this parent
75
64
  # @param debug_tag [:noface,Symbol,String] the tag (class name, value) used for debugging and in {#to_s}
76
65
  # @param child_type [nil,:key,:value] the next child's Mapping type, if +node+ is a Mapping
77
66
  def initialize(sniffer,node,debug_tag: nil,child_type: nil)
67
+ super(node)
68
+
78
69
  @child_position = 1
79
70
  @child_type = child_type
80
71
  @debug_tag = debug_tag
@@ -82,61 +73,61 @@ module Psychgus
82
73
  @node = node
83
74
  @position = sniffer.position
84
75
  end
85
-
76
+
86
77
  # @api private
87
78
  def __getobj__
88
79
  return @node
89
80
  end
90
-
81
+
91
82
  # Check if the children of this parent are keys to a Mapping.
92
- #
83
+ #
93
84
  # @return [true,false] whether the children are keys to a Mapping
94
- #
85
+ #
95
86
  # @since 1.2.0
96
- def child_key?()
87
+ def child_key?
97
88
  return @child_type == :key
98
89
  end
99
-
90
+
100
91
  # Check if the children of this parent are values to a Mapping (i.e., values to a key).
101
- #
92
+ #
102
93
  # @return [true,false] whether the children are values to a Mapping (i.e., values to a key)
103
- #
94
+ #
104
95
  # @since 1.2.0
105
- def child_value?()
96
+ def child_value?
106
97
  return @child_type == :value
107
98
  end
108
-
99
+
109
100
  # @see Psych::Nodes::Document#implicit
110
101
  # @see Psych::Nodes::Mapping#implicit
111
102
  # @see Psych::Nodes::Sequence#implicit
112
- def implicit?()
103
+ def implicit?
113
104
  return @node.implicit
114
105
  end
115
-
106
+
116
107
  # @see Psych::Nodes::Document#implicit_end
117
- def implicit_end?()
108
+ def implicit_end?
118
109
  return @node.implicit_end
119
110
  end
120
-
111
+
121
112
  # (see Ext::NodeExt#node_of?)
122
113
  def node_of?(*names)
123
114
  return @node.node_of?(*names)
124
115
  end
125
-
116
+
126
117
  # @see Psych::Nodes::Scalar#plain
127
- def plain?()
118
+ def plain?
128
119
  return @node.plain
129
120
  end
130
-
121
+
131
122
  # @see Psych::Nodes::Scalar#quoted
132
- def quoted?()
123
+ def quoted?
133
124
  return @node.quoted
134
125
  end
135
-
126
+
136
127
  # @note If this method is modified, then tests will fail
137
- #
128
+ #
138
129
  # @return [String] a String representation of this class for debugging and testing
139
- def to_s()
130
+ def to_s
140
131
  return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>"
141
132
  end
142
133
  end
@@ -1,27 +1,15 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of Psychgus.
7
- # Copyright (c) 2017-2019 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # Psychgus is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # Psychgus is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2017-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
24
12
  module Psychgus
25
13
  # Version of this gem in "#.#.#" format
26
- VERSION = '1.3.3'
14
+ VERSION = '1.3.4'
27
15
  end
data/psychgus.gemspec CHANGED
@@ -1,67 +1,63 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of Psychgus.
6
- # Copyright (c) 2017-2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # Psychgus is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with Psychgus. If not, see <https://www.gnu.org/licenses/>.
20
- #++
21
4
 
5
+ require_relative 'lib/psychgus/version'
22
6
 
23
- lib = File.expand_path('../lib',__FILE__)
24
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
7
 
26
- require 'psychgus/version'
27
-
28
-
29
- Gem::Specification.new() do |spec|
8
+ Gem::Specification.new do |spec|
30
9
  spec.name = 'psychgus'
31
10
  spec.version = Psychgus::VERSION
32
- spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
33
- spec.email = ['bradley@esotericpig.com']
11
+ spec.authors = ['Jonathan Bradley Whited']
12
+ spec.email = ['code@esotericpig.com']
34
13
  spec.licenses = ['LGPL-3.0-or-later']
35
14
  spec.homepage = 'https://github.com/esotericpig/psychgus'
36
- spec.summary = %q(Easily style YAML files using Psych.)
37
- spec.description = %q(Easily style YAML files using Psych, like Sequence/Mapping Flow style.)
38
-
15
+ spec.summary = 'Easily style YAML files using Psych.'
16
+ spec.description = 'Easily style YAML files using Psych, like Sequence/Mapping Flow style.'
17
+
39
18
  spec.metadata = {
19
+ 'homepage_uri' => 'https://github.com/esotericpig/psychgus',
20
+ 'source_code_uri' => 'https://github.com/esotericpig/psychgus',
40
21
  'bug_tracker_uri' => 'https://github.com/esotericpig/psychgus/issues',
41
22
  'changelog_uri' => 'https://github.com/esotericpig/psychgus/blob/master/CHANGELOG.md',
42
23
  'documentation_uri' => 'https://esotericpig.github.io/docs/psychgus/yardoc/index.html',
43
- 'homepage_uri' => 'https://github.com/esotericpig/psychgus',
44
- 'source_code_uri' => 'https://github.com/esotericpig/psychgus'
45
24
  }
46
-
47
- spec.require_paths = ['lib']
48
-
49
- spec.files = Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')) +
50
- Dir.glob(File.join('{test,yard}','**','*.{erb,rb}')) +
51
- %W( Gemfile #{spec.name}.gemspec Rakefile ) +
52
- %w( CHANGELOG.md LICENSE.txt README.md )
53
-
25
+
54
26
  spec.required_ruby_version = '>= 2.1.10'
55
-
27
+ spec.require_paths = ['lib']
28
+ spec.bindir = 'bin'
29
+
30
+ spec.files = [
31
+ Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')),
32
+ Dir.glob(File.join(spec.bindir,'*')),
33
+ Dir.glob(File.join('{samples,test,yard}','**','*.{erb,rb}')),
34
+ %W[ Gemfile #{spec.name}.gemspec Rakefile .yardopts ],
35
+ %w[ LICENSE.txt CHANGELOG.md README.md ],
36
+ ].flatten
37
+
38
+ # Test using different Gem versions:
39
+ # GST=1 bundle update && bundle exec rake test_all
40
+ gemspec_test = ENV.fetch('GST','').to_s.strip
41
+ psych_gemv = false
42
+
43
+ if !gemspec_test.empty?
44
+ case gemspec_test
45
+ when '1' then psych_gemv = '~> 3.0'
46
+ end
47
+
48
+ puts 'Using Gem versions:'
49
+ puts " psych: #{psych_gemv.inspect}"
50
+ end
51
+
56
52
  # 3.0 is needed for this issue:
57
53
  # - https://bugs.ruby-lang.org/issues/13115
58
54
  # - https://github.com/ruby/psych/commit/712a65a53f3c15105cd86e8ad3ee3c779050ada4
59
- spec.add_runtime_dependency 'psych','>= 3.0'
60
-
61
- spec.add_development_dependency 'bundler' ,'~> 2.1'
55
+ spec.add_runtime_dependency 'psych',psych_gemv || '>= 3.0'
56
+
57
+ spec.add_development_dependency 'bundler' ,'~> 2.2'
62
58
  spec.add_development_dependency 'minitest' ,'~> 5.14' # For testing
63
59
  spec.add_development_dependency 'rake' ,'~> 13.0'
64
- spec.add_development_dependency 'rdoc' ,'~> 6.2' # For RDoc for YARD (*.rb)
60
+ spec.add_development_dependency 'rdoc' ,'~> 6.3' # For RDoc for YARD (*.rb)
65
61
  spec.add_development_dependency 'redcarpet' ,'~> 3.5' # For Markdown for YARD (*.md)
66
62
  spec.add_development_dependency 'yard' ,'~> 0.9' # For documentation
67
63
  spec.add_development_dependency 'yard_ghurt','~> 1.2' # For YARD GitHub rake tasks
@@ -1,22 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  #--
5
5
  # This file is part of Psychgus.
6
- # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # Psychgus is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2019-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
11
 
@@ -24,23 +13,23 @@ require 'psychgus_tester'
24
13
 
25
14
  class Burger
26
15
  include Psychgus::Blueberry
27
-
16
+
28
17
  attr_accessor :bun
29
18
  attr_accessor :cheese
30
19
  attr_accessor :sauce
31
-
20
+
32
21
  def initialize(sauce,cheese,bun)
33
22
  @bun = bun
34
23
  @cheese = cheese
35
24
  @sauce = sauce
36
25
  end
37
-
26
+
38
27
  def encode_with(coder)
39
28
  coder['Bun'] = @bun
40
29
  coder['Cheese'] = @cheese
41
30
  coder['Sauce'] = @sauce
42
31
  end
43
-
32
+
44
33
  def psychgus_stylers(sniffer)
45
34
  return BurgerStyler.new(sniffer)
46
35
  end
@@ -49,21 +38,21 @@ end
49
38
  class Burgers
50
39
  attr_accessor :burgers
51
40
  attr_accessor :toppings
52
-
53
- def initialize()
41
+
42
+ def initialize
54
43
  @burgers = {
55
44
  'Classic' => Burger.new(['Ketchup','Mustard'],'American','Sesame Seed'),
56
45
  'BBQ' => Burger.new('Honey BBQ','Cheddar','Kaiser'),
57
46
  'Fancy' => Burger.new('Spicy Wasabi','Smoked Gouda','Hawaiian')
58
47
  }
59
-
48
+
60
49
  @toppings = [
61
50
  'Mushrooms',
62
- %w(Lettuce Onions Pickles Tomatoes),
63
- [%w(Ketchup Mustard),%w(Salt Pepper)]
51
+ %w[Lettuce Onions Pickles Tomatoes],
52
+ [%w[Ketchup Mustard],%w[Salt Pepper]]
64
53
  ]
65
54
  end
66
-
55
+
67
56
  def encode_with(coder)
68
57
  coder['Burgers'] = @burgers
69
58
  coder['Toppings'] = @toppings
@@ -72,46 +61,46 @@ end
72
61
 
73
62
  class BurgerStyler
74
63
  include Psychgus::Styler
75
-
64
+
76
65
  def initialize(sniffer)
77
66
  @level = sniffer.level
78
67
  @position = sniffer.position
79
68
  end
80
-
69
+
81
70
  def style(sniffer,node)
82
71
  # Remove ugly and unsafe "!ruby/object:Burger"
83
72
  node.tag = nil if node.respond_to?(:tag)
84
73
  end
85
-
74
+
86
75
  def style_mapping(sniffer,node)
87
76
  parent = sniffer.parent
88
-
89
- if !parent.nil?()
77
+
78
+ if !parent.nil?
90
79
  # BBQ
91
80
  node.style = Psychgus::MAPPING_FLOW if parent.respond_to?(:value) && parent.value.casecmp('BBQ') == 0
92
81
  end
93
82
  end
94
-
83
+
95
84
  def style_scalar(sniffer,node)
96
85
  # Only for Burgers
97
86
  node.style = Psychgus::SCALAR_SINGLE_QUOTED
98
87
  end
99
-
88
+
100
89
  def style_sequence(sniffer,node)
101
90
  relative_level = (sniffer.level - @level) + 1
102
-
91
+
103
92
  # [Ketchup, Mustard]
104
93
  node.style = Psychgus::SEQUENCE_FLOW if relative_level == 3
105
94
  end
106
95
  end
107
96
 
108
97
  class BlueberryTest < PsychgusTester
109
- def setup()
110
- @burgers = Burgers.new()
98
+ def setup
99
+ @burgers = Burgers.new
111
100
  end
112
-
113
- def test_blueberry()
114
- expected = <<-EOY
101
+
102
+ def test_blueberry
103
+ expected = <<-YAML
115
104
  |--- !ruby/object:Burgers
116
105
  |Burgers:
117
106
  | Classic:
@@ -133,9 +122,9 @@ class BlueberryTest < PsychgusTester
133
122
  | - Mustard
134
123
  | - - Salt
135
124
  | - Pepper
136
- EOY
125
+ YAML
137
126
  expected = self.class.lstrip_pipe(expected)
138
-
139
- assert_equal expected,@burgers.to_yaml()
127
+
128
+ assert_equal expected,@burgers.to_yaml
140
129
  end
141
130
  end