yarrow 0.5.1 → 0.6.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 +4 -4
- data/README.md +2 -6
- data/Rakefile +15 -1
- data/lib/yarrow/content/collection_expander.rb +0 -2
- data/lib/yarrow/schema.rb +109 -0
- data/lib/yarrow/schema/validations/array.rb +0 -0
- data/lib/yarrow/schema/validations/object.rb +0 -0
- data/lib/yarrow/schema/validations/string.rb +0 -0
- data/lib/yarrow/version.rb +3 -2
- data/lib/yarrow/web/html_document.rb +9 -0
- data/lib/yarrow/web/manifest.rb +9 -0
- data/lib/yarrow/web/static_asset.rb +9 -0
- data/lib/yarrow/web/template.rb +9 -0
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b1a14b73412ec27fad2ff75bd7944f1ef25f241779c532d3449339a436e4c32
|
4
|
+
data.tar.gz: 2cf2db75cc8c107b1d1bcbb6a79ad7fd92a6ba32e27413f2057158f7b8bb3c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 436cec2447208c2641d4ac332cbb1910b7b016983a0630782282a28fe34e7a929b4661f424f0002d937854316d00f6d822ec05407f40185a7d5bbd642a2b88d2
|
7
|
+
data.tar.gz: bd798c5d999b7d2665209778d507bfe9b54da98473850dd66b62c60391a270f93aa00d913315a7b29e6c92e7cb436f64fb89b692ecb4ea2da8bad5387d43b0b6
|
data/README.md
CHANGED
@@ -2,15 +2,11 @@ Yarrow
|
|
2
2
|
======
|
3
3
|
|
4
4
|
[][gem]
|
5
|
-
[][gemnasium]
|
7
|
-
[][codeclimate]
|
5
|
+
[][github]
|
8
6
|
[][coveralls]
|
9
7
|
|
10
8
|
[gem]: https://rubygems.org/gems/yarrow
|
11
|
-
[
|
12
|
-
[gemnasium]: https://gemnasium.com/maetl/yarrow
|
13
|
-
[codeclimate]: https://codeclimate.com/github/maetl/yarrow
|
9
|
+
[github]: https://github.com/maetl/yarrow
|
14
10
|
[coveralls]: https://coveralls.io/r/maetl/yarrow
|
15
11
|
|
16
12
|
Yarrow is a tool for generating well structured documentation from a variety of input sources.
|
data/Rakefile
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("./lib", __dir__)
|
2
|
+
require "yarrow"
|
3
|
+
|
4
|
+
task :version do
|
5
|
+
puts Yarrow::VERSION
|
6
|
+
end
|
7
|
+
|
8
|
+
task :build do
|
9
|
+
sh "gem build yarrow.gemspec"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :publish do
|
13
|
+
sh "gem push yarrow-#{Yarrow::VERSION}.gem"
|
14
|
+
end
|
1
15
|
|
2
16
|
task :clean do
|
3
|
-
sh
|
17
|
+
sh "rm yarrow-*.gem"
|
4
18
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Yarrow
|
2
|
+
module Schema
|
3
|
+
module Type
|
4
|
+
class Any
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Checks values plugged into each slot and runs any required validations
|
10
|
+
# (validations not yet implemented).
|
11
|
+
#
|
12
|
+
# Current design throws on error rather than returns a boolean result.
|
13
|
+
class Validator
|
14
|
+
# @param slots [Array<Symbol>, <Hash>] defines the slots in the schema to validate against
|
15
|
+
def initialize(slots)
|
16
|
+
@keys = slots.reduce({}) do |keys, slot|
|
17
|
+
if slot.is_a?(Array)
|
18
|
+
keys[slot[0]] = slot[1]
|
19
|
+
else
|
20
|
+
keys[slot.to_sym] = Type::Any
|
21
|
+
end
|
22
|
+
|
23
|
+
keys
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def check(fields)
|
28
|
+
raise "wrong number of args" unless fields.keys.length == @keys.keys.length
|
29
|
+
|
30
|
+
fields.keys.each do |key|
|
31
|
+
raise "key does not exist" unless @keys.key?(key)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Value object (with comparison by value equality). This just chucks back a
|
38
|
+
# Ruby struct but wraps the constructor with method advice that handles
|
39
|
+
# validation (and eventually type coercion if !yagni).
|
40
|
+
class Value
|
41
|
+
def self.new(*slots, &block)
|
42
|
+
factory(*slots, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.factory(*slots, &block)
|
46
|
+
validator = Validator.new(slots)
|
47
|
+
|
48
|
+
struct = Struct.new(*slots, keyword_init: true, &block)
|
49
|
+
|
50
|
+
struct.define_method :initialize do |kwargs|
|
51
|
+
validator.check(kwargs)
|
52
|
+
# TODO: type coercion or mapping decision goes here
|
53
|
+
super(**kwargs)
|
54
|
+
freeze
|
55
|
+
end
|
56
|
+
|
57
|
+
struct
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Entity with comparison by reference equality. Generates attribute helpers
|
63
|
+
# for a declared set of props. Used to replace Hashie::Mash without dragging
|
64
|
+
# in a whole new library.
|
65
|
+
class Entity
|
66
|
+
class << self
|
67
|
+
def attribute(name, value_type)
|
68
|
+
# define_method("map_#{name}".to_sym) do |input|
|
69
|
+
# value_type.coerce(input)
|
70
|
+
# end
|
71
|
+
dictionary[name] = value_type
|
72
|
+
attr_reader(name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def dictionary
|
76
|
+
@dictionary ||= Hash.new
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def dictionary
|
81
|
+
self.class.dictionary
|
82
|
+
end
|
83
|
+
|
84
|
+
def initialize(config)
|
85
|
+
dictionary.each_key do |name|
|
86
|
+
raise "missing declared attribute #{name}" unless dictionary.key?(name)
|
87
|
+
end
|
88
|
+
|
89
|
+
config.each_pair do |key, value|
|
90
|
+
raise "#{key} not a declared attribute" unless dictionary.key?(key)
|
91
|
+
|
92
|
+
defined_type = dictionary[key]
|
93
|
+
|
94
|
+
unless value.is_a?(defined_type)
|
95
|
+
raise "#{key} accepts #{defined_type} but #{value.class} given"
|
96
|
+
end
|
97
|
+
|
98
|
+
instance_variable_set("@#{key}", value)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_h
|
104
|
+
dictionary.keys.reduce({}) do |h, name|
|
105
|
+
h[name] = instance_variable_get("@#{name}")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/lib/yarrow/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yarrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
@@ -236,12 +236,20 @@ files:
|
|
236
236
|
- lib/yarrow/process/project_manifest.rb
|
237
237
|
- lib/yarrow/process/step_processor.rb
|
238
238
|
- lib/yarrow/process/workflow.rb
|
239
|
+
- lib/yarrow/schema.rb
|
240
|
+
- lib/yarrow/schema/validations/array.rb
|
241
|
+
- lib/yarrow/schema/validations/object.rb
|
242
|
+
- lib/yarrow/schema/validations/string.rb
|
239
243
|
- lib/yarrow/server.rb
|
240
244
|
- lib/yarrow/server/livereload.rb
|
241
245
|
- lib/yarrow/source/graph.rb
|
242
246
|
- lib/yarrow/tools/front_matter.rb
|
243
247
|
- lib/yarrow/tools/output_file.rb
|
244
248
|
- lib/yarrow/version.rb
|
249
|
+
- lib/yarrow/web/html_document.rb
|
250
|
+
- lib/yarrow/web/manifest.rb
|
251
|
+
- lib/yarrow/web/static_asset.rb
|
252
|
+
- lib/yarrow/web/template.rb
|
245
253
|
- yarrow.gemspec
|
246
254
|
homepage: http://rubygemspec.org/gems/yarrow
|
247
255
|
licenses:
|