yarrow 0.7.3 → 0.7.5

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: 0c49c3ae295fd127f7533a0af4c543d5315a2929a580a21b6b4c26379e519490
4
- data.tar.gz: 6867e3004c89dc7362a83378f3b0d55a14803d513cc77445c7893a31ffb4e4bd
3
+ metadata.gz: b067dcc24e059e6d5cfe506e6a3fc30b5679eb05e494ce842e515710ff60d170
4
+ data.tar.gz: c185b1f52f5b7aa173b26b179d47457f7705ef91460abd046ce3c81fa4733930
5
5
  SHA512:
6
- metadata.gz: '0056694b64f9ac4d000e85341570b4a5b630f27b5de15d5dcf12eeae1dc3625368abfd1d65a6c0a26f9793cbd6993e076c7e46d76ef97007874e8dddfd75c7af'
7
- data.tar.gz: fa5469997f6e674f3f2b1daf8bbc525637b2cbb2db7b9a8a1d494c85b1ce4d2725753ece2a2d114a905b994fe96f99e9db09178fa6f92483d4ee5d6208a500ad
6
+ metadata.gz: 33c522da6809b8ffbcd0457082a20a3222b877d086856413b815e141004769fdfc37998903d5f8b5a711dba21614323381fb2021f702082136b3f073b885abbf
7
+ data.tar.gz: a9b2a1ae9d015093709c7f64073809a470b058003ea98984ad1f8d6700cc65281e3e8aafc9e03ce9a669adf4e3800385f1727fe57cf5d54e95ac31862b603516
data/README.md CHANGED
@@ -40,7 +40,6 @@ A rough sketch of the project direction.
40
40
 
41
41
  | Version | Features |
42
42
  |---------|----------|
43
- | `0.6` | Default media type mapping, graph collectors, markup converters |
44
43
  | `0.7` | Content model/object mapping, template/site context |
45
44
  | `0.8` | HTML publishing workflow |
46
45
  | `0.9` | PDF publishing workflow |
data/bin/yarrow-server CHANGED
@@ -9,9 +9,9 @@ $:.unshift(File.join(File.dirname(File.expand_path(path)), '..', 'lib'))
9
9
 
10
10
  require 'yarrow'
11
11
 
12
- Yarrow::Configuration.register_defaults
12
+ config = Yarrow::Configuration.load_defaults
13
13
 
14
14
  Yarrow.logger = Logger.new(STDOUT)
15
15
 
16
- server = Yarrow::Server.new
16
+ server = Yarrow::Server.new(config)
17
17
  server.run
data/lib/yarrow/config.rb CHANGED
@@ -37,9 +37,9 @@ module Yarrow
37
37
  :port,
38
38
  :host,
39
39
  :handler,
40
- :docroot,
40
+ #:docroot,
41
41
  :middleware,
42
- :root_dir
42
+ #:root_dir
43
43
  )
44
44
 
45
45
  # Top level root config namespace.
@@ -18,7 +18,7 @@ assets:
18
18
  - js
19
19
  manifest_file: manifest.json
20
20
  server:
21
- live_reload: true
21
+ live_reload: false
22
22
  auto_index: true
23
23
  default_index: index.html
24
24
  default_type: text/plain
@@ -2,10 +2,12 @@ module Yarrow
2
2
  module Schema
3
3
  module Definitions
4
4
  DEFINED_TYPES = {
5
- string: Type::Raw[String],
6
- integer: Type::Raw[Integer],
7
- path: Type::Raw[Pathname],
8
- any: Type::Any
5
+ #string: Types::String,
6
+ string: Types::Instance.of(String),
7
+ #integer: Types::Integer,
8
+ integer: Types::Instance.of(Integer),
9
+ path: Types::Instance.of(Pathname),
10
+ any: Types::Any.new
9
11
  }
10
12
 
11
13
  def self.register(identifier, type_class)
@@ -23,6 +23,25 @@ module Yarrow
23
23
  @attrs_spec.keys
24
24
  end
25
25
 
26
+ def cast(input)
27
+ missing_attrs = @attrs_spec.keys.difference(input.keys)
28
+
29
+ if missing_attrs.any?
30
+ missing_attrs.each do |name|
31
+ raise "wrong number of attributes" unless @attrs_spec[name].is_a?(Types::Any)
32
+ end
33
+ end
34
+
35
+ mismatching_attrs = input.keys.difference(@attrs_spec.keys)
36
+
37
+ raise "attribute does not exist" if mismatching_attrs.any?
38
+
39
+ input.reduce({}) do |converted, (name, value)|
40
+ converted[name] = @attrs_spec[name].cast(value)
41
+ converted
42
+ end
43
+ end
44
+
26
45
  def check(input)
27
46
  missing_attrs = @attrs_spec.keys.difference(input.keys)
28
47
 
@@ -16,12 +16,9 @@ module Yarrow
16
16
  end
17
17
 
18
18
  def initialize(config)
19
- dictionary.check(config)
20
- # dictionary.each_key do |name|
21
- # raise "missing declared attribute #{name}" unless config.key?(name)
22
- # end
23
- #
24
- config.each_pair do |key, value|
19
+ converted = dictionary.cast(config)
20
+
21
+ converted.each_pair do |key, value|
25
22
  # raise "#{key} not a declared attribute" unless dictionary.key?(key)
26
23
  #
27
24
  # defined_type = dictionary[key]
@@ -9,13 +9,40 @@ module Yarrow
9
9
  def self.kind_of(t, u)
10
10
  new("#{t} is not a subclass of #{u}")
11
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
12
20
  end
13
21
 
14
22
  class TypeClass
15
- attr_reader :unit
23
+ def self.of(unit_type)
24
+ new(unit_type)
25
+ end
26
+
27
+ attr_reader :unit, :accepts
16
28
 
17
- def initialize(unit=nil)
18
- @unit = unit
29
+ def initialize(unit_type=nil)
30
+ @unit = unit_type
31
+ @accepts = {}
32
+ end
33
+
34
+ def accept(type, constructor)
35
+ accepts[type] = constructor
36
+ self
37
+ end
38
+
39
+ def should_coerce?(input)
40
+ accepts.key?(input.class)
41
+ end
42
+
43
+ def coerce(input)
44
+ constructor = accepts[input.class]
45
+ unit.send(constructor, input)
19
46
  end
20
47
 
21
48
  def check_instance_of!(input)
@@ -30,11 +57,22 @@ module Yarrow
30
57
  end
31
58
  end
32
59
 
33
- def check_respond_to!(input)
60
+ def check_respond_to_any!(input, methods)
61
+ unless methods.any? { |m| input.respond_to?(m) }
62
+ raise CastError.respond_to_any(input.class, methods)
63
+ end
64
+ end
34
65
 
66
+ def check_respond_to_all!(input, methods)
67
+ unless methods.all? { |m| input.respond_to?(m) }
68
+ raise CastError.respond_to_all(input.class, methods)
69
+ end
35
70
  end
36
71
 
37
- def cast(input); end
72
+ def cast(input)
73
+ return coerce(input) if should_coerce?(input)
74
+ check(input)
75
+ end
38
76
  end
39
77
 
40
78
  class Any < TypeClass
@@ -44,29 +82,47 @@ module Yarrow
44
82
  end
45
83
 
46
84
  class Instance < TypeClass
47
- def cast(input)
85
+ def check(input)
48
86
  check_instance_of!(input)
49
87
  input
50
88
  end
51
89
  end
52
90
 
53
- class Kind
54
- def cast(input)
91
+ class Kind < TypeClass
92
+ def check(input)
55
93
  check_kind_of!(input)
56
94
  input
57
95
  end
58
96
  end
59
97
 
60
- class Interface
61
-
62
- end
63
-
64
- class Optional
65
-
98
+ class Interface < TypeClass
99
+ def self.any(*args)
100
+ interface_type = new(args)
101
+ interface_type.implementation = :any
102
+ interface_type
103
+ end
104
+
105
+ def self.all(*args)
106
+ interface_type = new(args)
107
+ interface_type.implementation = :all
108
+ interface_type
109
+ end
110
+
111
+ attr_accessor :implementation
112
+
113
+ alias members unit
114
+
115
+ def check(input)
116
+ case implementation
117
+ when :any then check_respond_to_any!(input, members)
118
+ when :all then check_respond_to_all!(input, members)
119
+ end
120
+
121
+ input
122
+ end
66
123
  end
67
-
68
- class Constrained
69
-
124
+
125
+ class Union
70
126
  end
71
127
  end
72
128
  end
@@ -1,5 +1,16 @@
1
1
  module Yarrow
2
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
+
3
14
  # Value object (with comparison by value equality). This just chucks back a
4
15
  # Ruby struct but wraps the constructor with method advice that handles
5
16
  # type checking and conversion.
@@ -32,9 +43,9 @@ module Yarrow
32
43
  kwargs
33
44
  end
34
45
 
35
- validator.check(attr_values)
36
- # TODO: type coercion or mapping decision goes here
37
- super(**attr_values)
46
+ converted_values = validator.cast(attr_values)
47
+
48
+ super(**converted_values)
38
49
 
39
50
  freeze
40
51
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Yarrow
3
3
  APP_NAME = 'Yarrow'
4
- VERSION = '0.7.3'
4
+ VERSION = '0.7.5'
5
5
  end
data/lib/yarrow.rb CHANGED
@@ -5,7 +5,6 @@ require 'yarrow/version'
5
5
  require 'yarrow/extensions'
6
6
  require 'yarrow/symbols'
7
7
  require 'yarrow/logging'
8
- require 'yarrow/schema'
9
8
  require 'yarrow/schema/types'
10
9
  require 'yarrow/schema/definitions'
11
10
  require 'yarrow/schema/dictionary'
data/yarrow.gemspec CHANGED
@@ -14,7 +14,8 @@ 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'
@@ -24,7 +25,7 @@ Gem::Specification.new do |spec|
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.3
4
+ version: 0.7.5
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-10-08 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
@@ -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
@@ -228,7 +242,6 @@ files:
228
242
  - lib/yarrow/process/project_manifest.rb
229
243
  - lib/yarrow/process/step_processor.rb
230
244
  - lib/yarrow/process/workflow.rb
231
- - lib/yarrow/schema.rb
232
245
  - lib/yarrow/schema/definitions.rb
233
246
  - lib/yarrow/schema/dictionary.rb
234
247
  - lib/yarrow/schema/entity.rb
data/lib/yarrow/schema.rb DELETED
@@ -1,41 +0,0 @@
1
- require "delegate"
2
-
3
- module Yarrow
4
- module Schema
5
- module Type
6
- class Raw
7
- class << self
8
- def [](primitive)
9
- @primitive = primitive
10
- end
11
-
12
- def new(input)
13
- input
14
- end
15
- end
16
- end
17
-
18
- class Any
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
39
- end
40
- end
41
- end