yarrow 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/lib/yarrow/config.rb +4 -4
- data/lib/yarrow/schema/entity.rb +8 -10
- data/lib/yarrow/schema/value.rb +21 -12
- data/lib/yarrow/symbols.rb +14 -0
- data/lib/yarrow/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a2ebdee5113cc218a9744d5da88b01cb0e7604b4ecfe0d133f776d48d2b4b97
|
4
|
+
data.tar.gz: 967ba36fec57253eea8069f903828b8529f43802578c8be009413e4a5373e1f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 982f7c783ed933419504e6722e9ffbacaf513468a16cdb07ca4ec7ffc859d5eaed1470948d8c1ca7ce5aa00f5e0fc05b9c29a38f0f0e2972aa6d2f348aec2c7b
|
7
|
+
data.tar.gz: 4debe486afb56d7f664a0dd730db05429b2d7256a5f2789f1987339b394f404ac0f59f67d9e2f25126ad946675a46b7f910a91881d447afed148cb56eb4b5317
|
data/.github/workflows/ruby.yml
CHANGED
@@ -10,10 +10,10 @@ jobs:
|
|
10
10
|
fail-fast: false
|
11
11
|
matrix:
|
12
12
|
os: [ubuntu-latest, macos-latest]
|
13
|
-
ruby: [
|
13
|
+
ruby: [3.1, 3.2, "3.3.0-preview1"]
|
14
14
|
runs-on: ${{ matrix.os }}
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
17
|
- name: Set up Ruby
|
18
18
|
uses: ruby/setup-ruby@v1
|
19
19
|
with:
|
data/lib/yarrow/config.rb
CHANGED
@@ -53,13 +53,13 @@ module Yarrow
|
|
53
53
|
# Yarrow::Schema::Types::Map.of(Symbol)
|
54
54
|
# )
|
55
55
|
|
56
|
-
class Content < Yarrow::Schema::Entity
|
56
|
+
class Content < Yarrow::Schema::Entity
|
57
57
|
attribute :module, :string
|
58
58
|
#attribute :source_map, :__config_source_map
|
59
59
|
attribute :source_map, :hash
|
60
60
|
end
|
61
61
|
|
62
|
-
class Output < Yarrow::Schema::Entity
|
62
|
+
class Output < Yarrow::Schema::Entity
|
63
63
|
attribute :generator, :string
|
64
64
|
attribute :template_dir, :path
|
65
65
|
#attribute :scripts, :array
|
@@ -71,8 +71,8 @@ module Yarrow
|
|
71
71
|
attribute :output_dir, :path
|
72
72
|
attribute :meta, :any
|
73
73
|
attribute :server, :any
|
74
|
-
attribute :content, :
|
75
|
-
attribute :output, :
|
74
|
+
attribute :content, :yarrow_config_content
|
75
|
+
attribute :output, :yarrow_config_output
|
76
76
|
end
|
77
77
|
#
|
78
78
|
# `content_dir` and `output_dir` are placeholders and should be overriden
|
data/lib/yarrow/schema/entity.rb
CHANGED
@@ -20,11 +20,16 @@ module Yarrow
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def inherited(class_name)
|
23
|
+
class_type = Yarrow::Schema::Types::Instance.of(class_name).accept(Hash)
|
24
|
+
|
23
25
|
if @label
|
24
|
-
|
25
|
-
Yarrow::Schema::Definitions.register(@label, class_type)
|
26
|
+
label = @label
|
26
27
|
@label = nil
|
28
|
+
else
|
29
|
+
label = Yarrow::Symbols.from_const(class_name)
|
27
30
|
end
|
31
|
+
|
32
|
+
Yarrow::Schema::Definitions.register(label, class_type)
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
@@ -32,14 +37,7 @@ module Yarrow
|
|
32
37
|
converted = dictionary.cast(config)
|
33
38
|
|
34
39
|
converted.each_pair do |key, value|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# defined_type = dictionary[key]
|
38
|
-
#
|
39
|
-
# unless value.is_a?(defined_type)
|
40
|
-
# raise "#{key} accepts #{defined_type} but #{value.class} given"
|
41
|
-
# end
|
42
|
-
|
40
|
+
# TODO: should we represent this as an attribute set rather than instance vars?
|
43
41
|
instance_variable_set("@#{key}", value)
|
44
42
|
end
|
45
43
|
end
|
data/lib/yarrow/schema/value.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
module Yarrow
|
2
2
|
module Schema
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
class ValueType < Struct
|
4
|
+
def self.register(label)
|
5
|
+
class_type = Yarrow::Schema::Types::Instance.of(self).accept(Hash)
|
6
|
+
Yarrow::Schema::Definitions.register(label, class_type)
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
# Automatically register when struct is defined as a class extension
|
11
|
+
# rather than anonymous struct class.
|
12
|
+
def self.inherited(subclass)
|
13
|
+
if subclass.name
|
14
|
+
self.register(subclass.name.downcase.to_sym)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
13
18
|
|
14
19
|
# Value object (with comparison by value equality). This just chucks back a
|
15
20
|
# Ruby struct but wraps the constructor with method advice that handles
|
@@ -33,12 +38,16 @@ module Yarrow
|
|
33
38
|
|
34
39
|
validator = Dictionary.new(fields_spec)
|
35
40
|
|
36
|
-
struct =
|
41
|
+
struct = ValueType.new(*slots_spec, keyword_init: true, &block)
|
37
42
|
|
38
43
|
struct.define_method :initialize do |*args, **kwargs|
|
39
44
|
attr_values = if args.any?
|
40
45
|
raise ArgumentError.new("cannot mix slots and kwargs") if kwargs.any?
|
41
|
-
|
46
|
+
if args.first.instance_of?(Hash) and args.count == 1
|
47
|
+
args.first
|
48
|
+
else
|
49
|
+
Hash[slots.zip(args)]
|
50
|
+
end
|
42
51
|
else
|
43
52
|
kwargs
|
44
53
|
end
|
data/lib/yarrow/symbols.rb
CHANGED
@@ -19,6 +19,20 @@ module Yarrow
|
|
19
19
|
Object.const_get(Strings::Case.pascalcase(atom.to_s).to_sym)
|
20
20
|
end
|
21
21
|
|
22
|
+
# Converts a string name of class const to a symbol atom
|
23
|
+
#
|
24
|
+
# @param [Class, String, #to_s] const_obj
|
25
|
+
# @return [Symbol]
|
26
|
+
def self.from_const(const_obj)
|
27
|
+
const_lookup = if const_obj.respond_to?(:name)
|
28
|
+
const_obj.name
|
29
|
+
else
|
30
|
+
const_obj.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
Strings::Case.underscore(const_lookup).to_sym
|
34
|
+
end
|
35
|
+
|
22
36
|
# @param [Symbol, String] atom
|
23
37
|
# @return [Symbol]
|
24
38
|
def self.to_singular(atom)
|
data/lib/yarrow/version.rb
CHANGED
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.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|