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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee0d0048f5ad41b5bd0d8c0cb49059728e2920217876618294cc08997e450914
4
- data.tar.gz: e12fc19f4d9e973e522ae20e995bddf81c1e21861cfa26136cc3f03acf7f20b0
3
+ metadata.gz: 2a2ebdee5113cc218a9744d5da88b01cb0e7604b4ecfe0d133f776d48d2b4b97
4
+ data.tar.gz: 967ba36fec57253eea8069f903828b8529f43802578c8be009413e4a5373e1f1
5
5
  SHA512:
6
- metadata.gz: 81d64f248a17176116104d16f3d1e1a718aa5aa68eced9cc5eefa5ae8fb2d050bf43532c378a131010eab80125cb63360704790d62687287669f1a8c96bf91e3
7
- data.tar.gz: 1f3e90865e4a947a1615eb0ea190a35f7cf4b8d3b51de6a1e1d9b78391f7e47d7a480153aacdef51028debca6d6eeb58222017c480cb1c66b143e361fa762bb6
6
+ metadata.gz: 982f7c783ed933419504e6722e9ffbacaf513468a16cdb07ca4ec7ffc859d5eaed1470948d8c1ca7ce5aa00f5e0fc05b9c29a38f0f0e2972aa6d2f348aec2c7b
7
+ data.tar.gz: 4debe486afb56d7f664a0dd730db05429b2d7256a5f2789f1987339b394f404ac0f59f67d9e2f25126ad946675a46b7f910a91881d447afed148cb56eb4b5317
@@ -10,10 +10,10 @@ jobs:
10
10
  fail-fast: false
11
11
  matrix:
12
12
  os: [ubuntu-latest, macos-latest]
13
- ruby: [2.7, 3.1, 3.2]
13
+ ruby: [3.1, 3.2, "3.3.0-preview1"]
14
14
  runs-on: ${{ matrix.os }}
15
15
  steps:
16
- - uses: actions/checkout@v2
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[:__config_content]
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[:__config_output]
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, :__config_content
75
- attribute :output, :__config_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
@@ -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
- class_type = Yarrow::Schema::Types::Instance.of(class_name)
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
- # raise "#{key} not a declared attribute" unless dictionary.key?(key)
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
@@ -1,15 +1,20 @@
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
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 = Struct.new(*slots_spec, keyword_init: true, &block)
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
- Hash[slots.zip(args)]
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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Yarrow
3
3
  APP_NAME = "Yarrow"
4
- VERSION = "0.9.2"
4
+ VERSION = "0.9.3"
5
5
  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.9.2
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-06 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable