yarrow 0.7.2 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
1
+ module Yarrow
2
+ module Schema
3
+ module Types
4
+ class CastError < TypeError
5
+ def self.instance_of(t, u)
6
+ new("#{t} is not an instance of #{u}")
7
+ end
8
+
9
+ def self.kind_of(t, u)
10
+ new("#{t} is not a subclass of #{u}")
11
+ end
12
+
13
+ def self.respond_to_any(t, m)
14
+ new("#{t} does not implement any of #{m}")
15
+ end
16
+
17
+ def self.respond_to_all(t, m)
18
+ new("#{t} does not implement #{m}")
19
+ end
20
+ end
21
+
22
+ class TypeClass
23
+ def self.of(unit_type)
24
+ new(unit_type)
25
+ end
26
+
27
+ attr_reader :unit
28
+
29
+ def initialize(unit_type=nil)
30
+ @unit = unit_type
31
+ end
32
+
33
+ def check_instance_of!(input)
34
+ unless input.instance_of?(unit)
35
+ raise CastError.instance_of(input.class, unit)
36
+ end
37
+ end
38
+
39
+ def check_kind_of!(input)
40
+ unless input.kind_of?(unit)
41
+ raise CastError.kind_of(input.class, unit)
42
+ end
43
+ end
44
+
45
+ def check_respond_to_any!(input, methods)
46
+ unless methods.any? { |m| input.respond_to?(m) }
47
+ raise CastError.respond_to_any(input.class, methods)
48
+ end
49
+ end
50
+
51
+ def check_respond_to_all!(input, methods)
52
+ unless methods.all? { |m| input.respond_to?(m) }
53
+ raise CastError.respond_to_all(input.class, methods)
54
+ end
55
+ end
56
+
57
+ def cast(input); end
58
+ end
59
+
60
+ class Any < TypeClass
61
+ def cast(input)
62
+ input
63
+ end
64
+ end
65
+
66
+ class Instance < TypeClass
67
+ def cast(input)
68
+ check_instance_of!(input)
69
+ input
70
+ end
71
+ end
72
+
73
+ class Kind < TypeClass
74
+ def cast(input)
75
+ check_kind_of!(input)
76
+ input
77
+ end
78
+ end
79
+
80
+ class Interface < TypeClass
81
+ def self.any(*args)
82
+ interface_type = new(args)
83
+ interface_type.implementation = :any
84
+ interface_type
85
+ end
86
+
87
+ def self.all(*args)
88
+ interface_type = new(args)
89
+ interface_type.implementation = :all
90
+ interface_type
91
+ end
92
+
93
+ attr_accessor :implementation
94
+
95
+ alias members unit
96
+
97
+ def cast(input)
98
+ case implementation
99
+ when :any then check_respond_to_any!(input, members)
100
+ when :all then check_respond_to_all!(input, members)
101
+ end
102
+
103
+ input
104
+ end
105
+ end
106
+
107
+ class Union
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,57 @@
1
+ module Yarrow
2
+ module Schema
3
+ # class Structure < Struct
4
+ # def self.inherited(subclass)
5
+ # unless subclass.name
6
+ # puts "CLASS"
7
+ # p caller_locations[3]
8
+ # else
9
+ # p subclass.name.downcase.to_sym
10
+ # end
11
+ # end
12
+ # end
13
+
14
+ # Value object (with comparison by value equality). This just chucks back a
15
+ # Ruby struct but wraps the constructor with method advice that handles
16
+ # type checking and conversion.
17
+ class Value
18
+ def self.new(*slots, **fields, &block)
19
+ factory(*slots, **fields, &block)
20
+ end
21
+
22
+ def self.factory(*slots, **fields, &block)
23
+ if slots.empty? && fields.empty?
24
+ raise ArgumentError.new("missing attribute definition")
25
+ end
26
+
27
+ slots_spec, fields_spec = if fields.any?
28
+ raise ArgumentError.new("cannot use slots when field map is supplied") if slots.any?
29
+ [fields.keys, fields]
30
+ else
31
+ [slots, Hash[slots.map { |s| [s, :any]}]]
32
+ end
33
+
34
+ validator = Dictionary.new(fields_spec)
35
+
36
+ struct = Struct.new(*slots_spec, keyword_init: true, &block)
37
+
38
+ struct.define_method :initialize do |*args, **kwargs|
39
+ attr_values = if args.any?
40
+ raise ArgumentError.new("cannot mix slots and kwargs") if kwargs.any?
41
+ Hash[slots.zip(args)]
42
+ else
43
+ kwargs
44
+ end
45
+
46
+ validator.check(attr_values)
47
+ # TODO: type coercion or mapping decision goes here
48
+ super(**attr_values)
49
+
50
+ freeze
51
+ end
52
+
53
+ struct
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/yarrow/schema.rb CHANGED
@@ -1,132 +1,41 @@
1
+ require "delegate"
2
+
1
3
  module Yarrow
2
4
  module Schema
3
5
  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 fields_spec [Hash] defines the slots in the schema to validate against
15
- def initialize(fields_spec)
16
- @spec = fields_spec
17
- end
18
-
19
- def check(fields)
20
- missing_fields = @spec.keys.difference(fields.keys)
21
-
22
- if missing_fields.any?
23
- missing_fields.each do |field|
24
- raise "wrong number of args" unless @spec[field].eql?(Type::Any)
25
- end
26
- end
27
-
28
- mismatching_fields = fields.keys.difference(@spec.keys)
29
-
30
- raise "key does not exist" if mismatching_fields.any?
31
-
32
- fields.each do |(field, value)|
33
- raise "wrong data type" unless value.is_a?(@spec[field]) || @spec[field].eql?(Type::Any)
34
- end
35
-
36
- true
37
- end
38
- end
39
-
40
- ##
41
- # Value object (with comparison by value equality). This just chucks back a
42
- # Ruby struct but wraps the constructor with method advice that handles
43
- # validation (and eventually type coercion if !yagni).
44
- class Value
45
- def self.new(*slots, **fields, &block)
46
- factory(*slots, **fields, &block)
47
- end
48
-
49
- def self.factory(*slots, **fields, &block)
50
- if slots.empty? && fields.empty?
51
- raise ArgumentError.new("missing attribute definition")
52
- end
53
-
54
- slots_spec, fields_spec = if fields.any?
55
- raise ArgumentError.new("cannot use slots when field map is supplied") if slots.any?
56
- [fields.keys, fields]
57
- else
58
- [slots, Hash[slots.map { |s| [s, Type::Any]}]]
59
- end
60
-
61
- validator = Validator.new(fields_spec)
62
-
63
- struct = Struct.new(*slots_spec, keyword_init: true, &block)
64
-
65
- struct.define_method :initialize do |*args, **kwargs|
66
- attr_values = if args.any?
67
- raise ArgumentError.new("cannot mix slots and kwargs") if kwargs.any?
68
- Hash[slots.zip(args)]
69
- else
70
- kwargs
6
+ class Raw
7
+ class << self
8
+ def [](primitive)
9
+ @primitive = primitive
71
10
  end
72
11
 
73
- validator.check(attr_values)
74
- # TODO: type coercion or mapping decision goes here
75
- super(**attr_values)
76
-
77
- freeze
78
- end
79
-
80
- struct
81
- end
82
- end
83
-
84
- ##
85
- # Entity with comparison by reference equality. Generates attribute helpers
86
- # for a declared set of props. Used to replace Hashie::Mash without dragging
87
- # in a whole new library.
88
- class Entity
89
- class << self
90
- def attribute(name, value_type)
91
- # define_method("map_#{name}".to_sym) do |input|
92
- # value_type.coerce(input)
93
- # end
94
- dictionary[name] = value_type
95
- attr_reader(name)
96
- end
97
-
98
- def dictionary
99
- @dictionary ||= Hash.new
100
- end
101
- end
102
-
103
- def dictionary
104
- self.class.dictionary
105
- end
106
-
107
- def initialize(config)
108
- dictionary.each_key do |name|
109
- raise "missing declared attribute #{name}" unless dictionary.key?(name)
110
- end
111
-
112
- config.each_pair do |key, value|
113
- raise "#{key} not a declared attribute" unless dictionary.key?(key)
114
-
115
- defined_type = dictionary[key]
116
-
117
- unless value.is_a?(defined_type)
118
- raise "#{key} accepts #{defined_type} but #{value.class} given"
12
+ def new(input)
13
+ input
119
14
  end
120
-
121
- instance_variable_set("@#{key}", value)
122
15
  end
123
16
  end
124
- end
125
17
 
126
- def to_h
127
- dictionary.keys.reduce({}) do |h, name|
128
- h[name] = instance_variable_get("@#{name}")
18
+ class Any
129
19
  end
20
+ # class Attribute
21
+ # class << self
22
+ # def accepts(attr_type)
23
+ # @accepts = attr_type
24
+ # end
25
+ # end
26
+ #
27
+ # attr_accessor :value
28
+ # alias_method :__getobj__, :value
29
+ #
30
+ # def initialize(value)
31
+ # raise "Invalid type" unless @accepts.is_a?(value.class)
32
+ # @value = value
33
+ # end
34
+ # end
35
+ #
36
+ # class Text < Attribute
37
+ # accepts String
38
+ # end
130
39
  end
131
40
  end
132
41
  end
data/lib/yarrow/server.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rack'
2
+ require 'rackup'
2
3
 
3
4
  module Yarrow
4
5
  ##
@@ -52,8 +53,8 @@ module Yarrow
52
53
  @app = app
53
54
  end
54
55
 
55
- def should_try_rewrite(path)
56
- !request_path.ends_with(".html") || !request_path.ends_with("/")
56
+ def should_try_rewrite(request_path)
57
+ !request_path.end_with?(".html") || !request_path.end_with?("/")
57
58
  end
58
59
 
59
60
  def call(env)
@@ -123,14 +124,14 @@ module Yarrow
123
124
  reactor.start
124
125
  end
125
126
 
126
- handler = Rack::Handler.get(run_options[:server])
127
+ handler = Rackup::Handler.get(run_options[:server])
127
128
 
128
129
  trap(:INT) do
129
130
  handler.shutdown if handler.respond_to?(:shutdown)
130
131
  reactor.stop if live_reload?
131
132
  end
132
133
 
133
- handler.run(app, run_options)
134
+ handler.run(app, **run_options)
134
135
  end
135
136
 
136
137
  private
@@ -3,15 +3,30 @@ require "strings-case"
3
3
 
4
4
  module Yarrow
5
5
  module Symbols
6
+ # @param [Array<String>, Array<Symbol>] parts
7
+ # @return [Object]
8
+ def self.to_module_const(parts)
9
+ Object.const_get(parts.map { |atom|
10
+ Strings::Case.pascalcase(atom.to_s)
11
+ }.join("::"))
12
+ end
13
+
6
14
  # Converts an atomic content identifier to a live class constant.
15
+ #
16
+ # @param [Symbol, String] atom
17
+ # @return [Object]
7
18
  def self.to_const(atom)
8
19
  Object.const_get(Strings::Case.pascalcase(atom.to_s).to_sym)
9
20
  end
10
21
 
22
+ # @param [Symbol, String] atom
23
+ # @return [Symbol]
11
24
  def self.to_singular(atom)
12
25
  Strings::Inflection.singularize(atom.to_s).to_sym
13
26
  end
14
27
 
28
+ # @param [Symbol, String] atom
29
+ # @return [Symbol]
15
30
  def self.to_plural(atom)
16
31
  Strings::Inflection.pluralize(atom.to_s).to_sym
17
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Yarrow
3
3
  APP_NAME = 'Yarrow'
4
- VERSION = '0.7.2'
4
+ VERSION = '0.7.4'
5
5
  end
data/lib/yarrow.rb CHANGED
@@ -6,18 +6,25 @@ require 'yarrow/extensions'
6
6
  require 'yarrow/symbols'
7
7
  require 'yarrow/logging'
8
8
  require 'yarrow/schema'
9
+ require 'yarrow/schema/types'
10
+ require 'yarrow/schema/definitions'
11
+ require 'yarrow/schema/dictionary'
12
+ require 'yarrow/schema/entity'
13
+ require 'yarrow/schema/value'
9
14
  require 'yarrow/config'
10
15
  require 'yarrow/configuration'
11
16
  require 'yarrow/console_runner'
12
17
  require 'yarrow/tools/front_matter'
13
18
  require 'yarrow/tools/content_utils'
14
19
  require 'yarrow/content/graph'
15
- require 'yarrow/content/object_type'
16
- require 'yarrow/content/source_collector'
17
- require 'yarrow/content/collection_expander'
20
+ require 'yarrow/content/source'
18
21
  require 'yarrow/content/expansion'
22
+ require 'yarrow/content/expansion_strategy'
19
23
  require 'yarrow/content/tree_expansion'
20
24
  require 'yarrow/content/manifest'
25
+ require 'yarrow/content/resource'
26
+ require 'yarrow/content/model'
27
+ require 'yarrow/content/policy'
21
28
  require 'yarrow/output/mapper'
22
29
  require 'yarrow/output/generator'
23
30
  require 'yarrow/output/context'
data/yarrow.gemspec CHANGED
@@ -14,17 +14,18 @@ Gem::Specification.new do |spec|
14
14
  spec.executables << 'yarrow'
15
15
  spec.executables << 'yarrow-server'
16
16
  spec.add_runtime_dependency 'mementus', '~> 0.8'
17
- spec.add_runtime_dependency 'rack', '~> 2.0'
17
+ spec.add_runtime_dependency 'rack', '~> 3.0'
18
+ spec.add_runtime_dependency 'rackup', '~> 0.2'
18
19
  spec.add_runtime_dependency 'rack-livereload', '~> 0.3'
19
20
  spec.add_runtime_dependency 'eventmachine', '~> 1.2'
20
21
  spec.add_runtime_dependency 'em-websocket', '~> 0.5.1'
21
22
  spec.add_runtime_dependency 'strings-inflection', '~> 0.1'
22
23
  spec.add_runtime_dependency 'strings-case', '~> 0.3'
23
- spec.add_development_dependency 'bundler'
24
+ spec.add_runtime_dependency 'kramdown', '~> 2.4.0'
24
25
  spec.add_development_dependency 'rake', '~> 13.0'
25
26
  spec.add_development_dependency 'rspec', '~> 3.11'
26
27
  spec.add_development_dependency 'coveralls', '~> 0.8.23'
27
- spec.add_development_dependency 'rack-test', '~> 0.8'
28
+ spec.add_development_dependency 'rack-test', '~> 2.0'
28
29
  spec.homepage = 'http://rubygemspec.org/gems/yarrow'
29
30
  spec.license = 'MIT'
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yarrow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mementus
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rackup
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rack-livereload
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,19 +123,19 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0.3'
111
125
  - !ruby/object:Gem::Dependency
112
- name: bundler
126
+ name: kramdown
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
131
+ version: 2.4.0
132
+ type: :runtime
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: 2.4.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rake
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +184,14 @@ dependencies:
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '0.8'
187
+ version: '2.0'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '0.8'
194
+ version: '2.0'
181
195
  description: Yarrow is a tool for generating well structured documentation from a
182
196
  variety of input sources.
183
197
  email: me@maetl.net
@@ -203,13 +217,14 @@ files:
203
217
  - lib/yarrow/config.rb
204
218
  - lib/yarrow/configuration.rb
205
219
  - lib/yarrow/console_runner.rb
206
- - lib/yarrow/content/collection_expander.rb
207
220
  - lib/yarrow/content/expansion.rb
221
+ - lib/yarrow/content/expansion_strategy.rb
208
222
  - lib/yarrow/content/graph.rb
209
223
  - lib/yarrow/content/manifest.rb
210
- - lib/yarrow/content/object_type.rb
224
+ - lib/yarrow/content/model.rb
225
+ - lib/yarrow/content/policy.rb
226
+ - lib/yarrow/content/resource.rb
211
227
  - lib/yarrow/content/source.rb
212
- - lib/yarrow/content/source_collector.rb
213
228
  - lib/yarrow/content/tree_expansion.rb
214
229
  - lib/yarrow/content_map.rb
215
230
  - lib/yarrow/defaults.yml
@@ -228,9 +243,14 @@ files:
228
243
  - lib/yarrow/process/step_processor.rb
229
244
  - lib/yarrow/process/workflow.rb
230
245
  - lib/yarrow/schema.rb
246
+ - lib/yarrow/schema/definitions.rb
247
+ - lib/yarrow/schema/dictionary.rb
248
+ - lib/yarrow/schema/entity.rb
249
+ - lib/yarrow/schema/types.rb
231
250
  - lib/yarrow/schema/validations/array.rb
232
251
  - lib/yarrow/schema/validations/object.rb
233
252
  - lib/yarrow/schema/validations/string.rb
253
+ - lib/yarrow/schema/value.rb
234
254
  - lib/yarrow/server.rb
235
255
  - lib/yarrow/server/livereload.rb
236
256
  - lib/yarrow/source/graph.rb
@@ -262,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
282
  - !ruby/object:Gem::Version
263
283
  version: '0'
264
284
  requirements: []
265
- rubygems_version: 3.1.2
285
+ rubygems_version: 3.3.7
266
286
  signing_key:
267
287
  specification_version: 4
268
288
  summary: Documentation generator based on a fluent data model.