saga 0.13.2 → 0.14.0

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
  SHA256:
3
- metadata.gz: 4094964e1d44aed093bd97b5b9996553ae8588c5da221193a36800fcbca0e5d9
4
- data.tar.gz: 043da35cf45444bf5518cd1ace35484e0acb8aba25c603cc024d7d1282b07d68
3
+ metadata.gz: beaae8ecc51e2ef96e5343ffc064ab3290f490f722e44c68fa3a766986161371
4
+ data.tar.gz: 9ccabb4c4e6ea3563d893bfe04054aebfd954fd26e825415bb56735003d64f08
5
5
  SHA512:
6
- metadata.gz: 795bdf665843a8b3f947b1d8adf9ae02720f8f2974916f3406122d7873d98572954b80d7feb54cd0cc7328917ddd90bbeeae87113de4a7944a497c8a1f5c6b9b
7
- data.tar.gz: 304432814c5a89f48ff6fde9e9e4f89e573ea35ff8cb1fed8f64f8f64cc8afe95acb5ff99bdad4f68f4eea407ab5b72f82ecae0478bbac561e8fa258ef6fd1cb
6
+ metadata.gz: add20ee8c3436a11c6141ec3e9e9ed82c9a16f4965894bb044633b5846cc8df4fe047f6b81fe12aad6ef167a65426b1a8f98c643e0a23a8110adb5bbbcf6bd9a
7
+ data.tar.gz: 0772c7c89c5cd0ae6f1f6b1bc1aad3e3a48e44163fed93d6104c5e1ecb5e3d42ea052674bcec8c5ecf87e034217aad2e72f5a4afc301d1f38ef0ae66cd7cf23a
data/lib/saga/runner.rb CHANGED
@@ -26,6 +26,7 @@ module Saga
26
26
  parser.separator ' autofill <filename> - adds an id to stories without one'
27
27
  parser.separator ' planning <filename> - shows the planning of stories in iterations'
28
28
  parser.separator ' template <dir> - creates a template directory'
29
+ parser.separator ' verify <dir> - checks internal consistency of the document'
29
30
  parser.separator ''
30
31
  parser.separator 'Options:'
31
32
  parser.on('-t', '--template DIR', 'Use an external template for conversion to HTML') do |template_path|
@@ -96,20 +97,26 @@ module Saga
96
97
  end
97
98
  end
98
99
 
100
+ def verify(filename)
101
+ Saga::Verifier.new(Saga::Parser.parse(File.read(filename))).run
102
+ end
103
+
99
104
  def run_command(command)
100
105
  case command
101
106
  when 'new'
102
107
  puts new_file
103
108
  when 'convert'
104
- puts convert(File.expand_path(@argv[0]))
109
+ puts convert(file_path)
105
110
  when 'inspect'
106
- write_parsed_document(File.expand_path(@argv[0]))
111
+ write_parsed_document(file_path)
107
112
  when 'autofill'
108
- puts autofill(File.expand_path(@argv[0]))
113
+ puts autofill(file_path)
109
114
  when 'planning'
110
- puts planning(File.expand_path(@argv[0]))
115
+ puts planning(file_path)
111
116
  when 'template'
112
- copy_template(File.expand_path(@argv[0]))
117
+ copy_template(file_path)
118
+ when 'verify'
119
+ verify(file_path)
113
120
  else
114
121
  puts convert(File.expand_path(command))
115
122
  end
@@ -128,5 +135,9 @@ module Saga
128
135
  def author
129
136
  { name: `osascript -e "long user name of (system info)" &1> /dev/null`.strip }
130
137
  end
138
+
139
+ def file_path
140
+ File.expand_path(@argv[0])
141
+ end
131
142
  end
132
143
  end
@@ -0,0 +1,70 @@
1
+ module Saga
2
+ class Verifier
3
+ attr_reader :document
4
+
5
+ def initialize(document)
6
+ @document = document
7
+ end
8
+
9
+ def structure
10
+ @structure ||= build_structure
11
+ end
12
+
13
+ def run
14
+ return if structure.empty?
15
+
16
+ reported = []
17
+ structure.each do |title, details|
18
+ if details[:duplicates].any?
19
+ warning = "has multiple stories with the same id: " \
20
+ "#{format_sentence(details[:duplicates])}"
21
+ if title.strip != ""
22
+ puts "* Section #{format_title(title)} #{warning}"
23
+ else
24
+ puts "* Document #{warning}"
25
+ end
26
+ end
27
+
28
+ structure.each do |other_title, other_details|
29
+ next if title == other_title
30
+
31
+ reused = details[:ids] & other_details[:ids]
32
+ if reused.any?
33
+ pair = [title, other_title].sort
34
+ unless reported.include?(pair)
35
+ puts(
36
+ "* Sections #{format_title(title)} and #{format_title(other_title)} " \
37
+ "share story ids: #{format_sentence(reused)}"
38
+ )
39
+ reported << pair
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def build_structure
49
+ document.stories.each.with_object({}) do |(title, stories), structure|
50
+ structure[title] ||= {}
51
+ ids = stories.map { |story| story[:id] }
52
+ structure[title][:ids] = ids
53
+ structure[title][:duplicates] = ids.uniq.select { |id| ids.count(id) > 1 }
54
+ end
55
+ end
56
+
57
+ def format_title(title)
58
+ %("#{title}")
59
+ end
60
+
61
+ def format_sentence(items)
62
+ case items.size
63
+ when 0, 1, 2
64
+ items.join(" and ")
65
+ else
66
+ format_sentence(items[..-2].join(", "), items[-1])
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/saga/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Saga
4
- VERSION = '0.13.2'.freeze
4
+ VERSION = '0.14.0'.freeze
5
5
  end
data/lib/saga.rb CHANGED
@@ -5,6 +5,7 @@ module Saga
5
5
  autoload :Planning, 'saga/planning'
6
6
  autoload :Runner, 'saga/runner'
7
7
  autoload :Tokenizer, 'saga/tokenizer'
8
+ autoload :Verifier, 'saga/verifier'
8
9
 
9
10
  def self.run(argv)
10
11
  runner = ::Saga::Runner.new(argv)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -58,6 +57,7 @@ files:
58
57
  - lib/saga/planning.rb
59
58
  - lib/saga/runner.rb
60
59
  - lib/saga/tokenizer.rb
60
+ - lib/saga/verifier.rb
61
61
  - lib/saga/version.rb
62
62
  - templates/default/document.erb
63
63
  - templates/default/helpers.rb
@@ -68,7 +68,6 @@ homepage: https://github.com/Fingertips/saga
68
68
  licenses:
69
69
  - MIT
70
70
  metadata: {}
71
- post_install_message:
72
71
  rdoc_options: []
73
72
  require_paths:
74
73
  - lib
@@ -83,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
82
  - !ruby/object:Gem::Version
84
83
  version: '0'
85
84
  requirements: []
86
- rubygems_version: 3.0.4
87
- signing_key:
85
+ rubygems_version: 3.6.9
88
86
  specification_version: 4
89
87
  summary: Saga is a tool to convert stories syntax to a nicely formatted document.
90
88
  test_files: []