easy_talk 0.1.6 → 0.1.8

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: ef35c90e8f4ecd74af7743e5c4e8503a3f1df9099c4395c5d8376d8b7be2f325
4
- data.tar.gz: 85e4bec40186ed896834b59707ad68a9ede133db9fe1c4da99570de416f8abb9
3
+ metadata.gz: da6e2b2c29860236280b654d18e4df4af908ab0246f01e1e5e376805f8359d37
4
+ data.tar.gz: 1a36d4e08f82069391386c3b2bd03becfeaea198657b8db05ff2ebda793d4ec8
5
5
  SHA512:
6
- metadata.gz: 0a74dd4133b14bb81882224e06c97488be0ac1e85e4c3a52452c3ce396a52928aefc13de45a7e284c846ae8acc09e73043381bb46d9acad7cfcfdfcf5e290a45
7
- data.tar.gz: 0f78ef87354030469e5c9b8897331870a1232724bc33a2e6d0af7bffaf44617f86e8ecd4a44684955d964d9dd55fbdca5944a14699db49fc981d0803a31489a9
6
+ metadata.gz: 9026006c5e296adf2f3a7c826757ffe4b17a1387c3621907442ac47293d2d7d89eb4779fe3863ef24f6a8fc34174a7b4e7e22d2aaf0a26a4534ddc65f08ab482
7
+ data.tar.gz: d3cd70fb2ac65241cf395606d0eae55e2282006578f4f78096f9e03256ae6fa91bd371b0874d20aa797667b4972be4ff91c5b38b4396ee1be89a3b4d057d4681
data/.rubocop.yml CHANGED
@@ -1,5 +1,17 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  TargetRubyVersion: 3.2
7
+
8
+ RSpec/FilePath:
9
+ SpecSuffixOnly: true
10
+
11
+ RSpec/ExampleLength:
12
+ Max: 10
13
+ Exclude:
14
+ - 'spec/easy_talk/examples/**/*'
3
15
 
4
16
  Metrics/BlockLength:
5
17
  Exclude:
@@ -11,4 +23,8 @@ Lint/ConstantDefinitionInBlock:
11
23
 
12
24
  Layout/LineLength:
13
25
  Exclude:
14
- - 'spec/**/*'
26
+ - 'spec/**/*'
27
+
28
+ RSpec/DescribeClass:
29
+ Exclude:
30
+ - 'spec/easy_talk/examples/**/*'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.1.8] - 2024-04-24
2
+ - mostly refactoring without changes to the public API.
3
+
4
+ ## [0.1.7] - 2024-04-16
5
+ - general cleanup and refactoring.
6
+
1
7
  ## [0.1.6] - 2024-04-16
2
8
  - model instance takes a hash and converts it to attribute methods.
3
9
 
data/Rakefile CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
8
- require 'rubocop/rake_task'
9
-
10
9
  RuboCop::RakeTask.new
11
10
 
12
11
  task default: %i[spec rubocop]
@@ -53,6 +53,10 @@ module EasyTalk
53
53
  obj[value[:key]] = T.let(@options[key], value[:type])
54
54
  end
55
55
  end
56
+
57
+ def self.collection_type?
58
+ false
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -11,12 +11,11 @@ module EasyTalk
11
11
  # VALID_OPTIONS defines the valid options for a boolean property.
12
12
  VALID_OPTIONS = {
13
13
  enum: { type: T::Array[T::Boolean], key: :enum },
14
- const: { type: T::Boolean, key: :const },
15
14
  default: { type: T::Boolean, key: :default }
16
15
  }.freeze
17
16
 
18
- sig { params(name: Symbol, _type: T.untyped, constraints: Hash).void }
19
- def initialize(name, _type = nil, constraints = {})
17
+ sig { params(name: Symbol, constraints: Hash).void }
18
+ def initialize(name, constraints = {})
20
19
  super(name, { type: 'boolean' }, constraints, VALID_OPTIONS)
21
20
  end
22
21
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasyTalk
4
+ module Builders
5
+ # Base builder class for array-type properties.
6
+ module CollectionHelpers
7
+ def collection_type?
8
+ true
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base_builder'
3
+ require_relative 'collection_helpers'
4
4
 
5
5
  module EasyTalk
6
6
  module Builders
7
7
  # This class represents a builder for composing JSON schemas using the "allOf", "anyOf", or "oneOf" keywords.
8
8
  class CompositionBuilder
9
+ extend CollectionHelpers
9
10
  extend T::Sig
10
11
 
11
12
  COMPOSER_TO_KEYWORD = {
@@ -19,8 +19,8 @@ module EasyTalk
19
19
  }.freeze
20
20
 
21
21
  # Initializes a new instance of the IntegerBuilder class.
22
- sig { params(name: Symbol, _type: T.untyped, constraints: Hash).void }
23
- def initialize(name, _type = nil, constraints = {})
22
+ sig { params(name: Symbol, constraints: Hash).void }
23
+ def initialize(name, constraints = {})
24
24
  super(name, { type: 'integer' }, constraints, VALID_OPTIONS)
25
25
  end
26
26
  end
@@ -7,8 +7,8 @@ module EasyTalk
7
7
  # builder class for Null properties.
8
8
  class NullBuilder < BaseBuilder
9
9
  # Initializes a new instance of the NullBuilder class.
10
- sig { params(name: Symbol, _type: T.untyped, _constraints: Hash).void }
11
- def initialize(name, _type = nil, _constraints = {})
10
+ sig { params(name: Symbol, _constraints: Hash).void }
11
+ def initialize(name, _constraints = {})
12
12
  super(name, { type: 'null' }, {}, {})
13
13
  end
14
14
  end
@@ -18,8 +18,8 @@ module EasyTalk
18
18
  }.freeze
19
19
 
20
20
  # Initializes a new instance of the NumberBuilder class.
21
- sig { params(name: Symbol, _type: T.untyped, constraints: Hash).void }
22
- def initialize(name, _type = nil, constraints = {})
21
+ sig { params(name: Symbol, constraints: Hash).void }
22
+ def initialize(name, constraints = {})
23
23
  super(name, { type: 'number' }, constraints, VALID_OPTIONS)
24
24
  end
25
25
  end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'base_builder'
4
+
3
5
  module EasyTalk
4
6
  module Builders
5
7
  # Builder class for json schema objects.
6
8
  class ObjectBuilder < BaseBuilder
7
9
  extend T::Sig
8
10
 
9
- attr_reader :klass, :schema
11
+ attr_reader :schema
10
12
 
11
13
  VALID_OPTIONS = {
12
14
  properties: { type: T::Hash[Symbol, T.untyped], key: :properties },
@@ -18,8 +18,8 @@ module EasyTalk
18
18
  default: { type: String, key: :default }
19
19
  }.freeze
20
20
 
21
- sig { params(name: Symbol, _type: T.untyped, constraints: Hash).void }
22
- def initialize(name, _type = nil, constraints = {})
21
+ sig { params(name: Symbol, constraints: Hash).void }
22
+ def initialize(name, constraints = {})
23
23
  super(name, { type: 'string' }, constraints, VALID_OPTIONS)
24
24
  end
25
25
  end
@@ -1,9 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'collection_helpers'
4
+
3
5
  module EasyTalk
4
6
  module Builders
5
7
  # Builder class for array properties.
6
8
  class TypedArrayBuilder < BaseBuilder
9
+ extend CollectionHelpers
10
+ extend T::Sig
11
+
7
12
  VALID_OPTIONS = {
8
13
  min_items: { type: Integer, key: :minItems },
9
14
  max_items: { type: Integer, key: :maxItems },
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base_builder'
3
+ require_relative 'collection_helpers'
4
4
 
5
5
  module EasyTalk
6
6
  module Builders
7
7
  # Base builder class for array-type properties.
8
8
  class UnionBuilder
9
+ extend CollectionHelpers
9
10
  extend T::Sig
11
+
10
12
  sig { params(name: Symbol, type: T.untyped, constraints: T.untyped).void }
11
13
  def initialize(name, type, constraints)
12
14
  @name = name
@@ -7,54 +7,14 @@ require 'active_support/time'
7
7
  require 'active_support/concern'
8
8
  require 'active_support/json'
9
9
  require 'json-schema'
10
- require_relative 'builder'
10
+ require_relative 'builders/object_builder'
11
11
  require_relative 'schema_definition'
12
12
 
13
13
  module EasyTalk
14
14
  # The Model module can be included in a class to add JSON schema definition and generation support.
15
15
  module Model
16
- def self.included(base)
17
- base.extend(ClassMethods)
18
-
19
- base.singleton_class.instance_eval do
20
- define_method(:inherited) do |subclass|
21
- super(subclass)
22
- subclass.extend(SubclassExtension)
23
- end
24
- end
25
- end
26
-
27
- def initialize(properties = {})
28
- properties.each do |key, value|
29
- instance_variable_set("@#{key}", value)
30
- self.class.class_eval { attr_reader key }
31
- end
32
- end
33
-
34
- def valid?
35
- self.class.validate_json(properties)
36
- end
37
-
38
- def properties
39
- as_json.symbolize_keys!
40
- end
41
-
42
- # This module provides extension methods for subclasses with schema definitions.
43
- module SubclassExtension
44
- # Returns true if the class inherits a schema.
45
- def inherits_schema?
46
- true
47
- end
48
-
49
- # Returns the superclass that the class inherits from.
50
- def inherits_from
51
- superclass
52
- end
53
- end
54
-
55
- # Module containing class-level methods for defining and accessing the schema of a model.
16
+ # The `Model` module is a mixin that provides functionality for defining and accessing the schema of a model.
56
17
  #
57
- # This module provides methods for defining and accessing the JSON schema of a model.
58
18
  # It includes methods for defining the schema, retrieving the schema definition,
59
19
  # and generating the JSON schema for the model.
60
20
  #
@@ -83,37 +43,85 @@ module EasyTalk
83
43
  # MyModel.json_schema #=> returns the JSON schema for MyModel
84
44
  #
85
45
  # @see SchemaDefinition
86
- # @see Builder
46
+ #
47
+ def self.included(base)
48
+ base.extend(ClassMethods)
49
+ end
50
+
51
+ # Initializes a new instance of the Model class.
52
+ #
53
+ # @param properties [Hash] The properties to set for the instance.
54
+ def initialize(properties = {})
55
+ properties.each do |key, value|
56
+ instance_variable_set("@#{key}", value)
57
+ self.class.class_eval { attr_reader key }
58
+ end
59
+ end
60
+
61
+ # Checks if the model is valid.
62
+ #
63
+ # This method calls the `validate_json` class method on the current class,
64
+ # passing the `properties` as the argument.
65
+ #
66
+ # @return [Boolean] true if the model is valid, false otherwise.
67
+ def valid?
68
+ self.class.validate_json(properties)
69
+ end
70
+
71
+ # Returns the properties of the model as a hash with symbolized keys.
72
+ def properties
73
+ as_json.symbolize_keys!
74
+ end
75
+
76
+ # Module containing class-level methods for defining and accessing the schema of a model.
87
77
  module ClassMethods
78
+ # Returns the schema for the model.
79
+ #
80
+ # @return [Schema] The schema for the model.
88
81
  def schema
89
- @schema ||= Builder.new(schema_definition).schema
82
+ @schema ||= build_schema(schema_definition)
90
83
  end
91
84
 
85
+ # Returns true if the class inherits a schema.
86
+ #
87
+ # @return [Boolean] `true` if the class inherits a schema, `false` otherwise.
92
88
  def inherits_schema?
93
89
  false
94
90
  end
95
91
 
92
+ # Returns the reference template for the model.
93
+ #
94
+ # @return [String] The reference template for the model.
96
95
  def ref_template
97
96
  "#/$defs/#{name}"
98
97
  end
99
98
 
99
+ # Returns the name of the model as a human-readable function name.
100
+ #
101
+ # @return [String] The human-readable function name of the model.
100
102
  def function_name
101
103
  name.humanize.titleize
102
104
  end
103
105
 
106
+ # Validates the given JSON against the model's JSON schema.
107
+ #
108
+ # @param json [Hash] The JSON to validate.
109
+ # @return [Boolean] `true` if the JSON is valid, `false` otherwise.
104
110
  def validate_json(json)
105
111
  JSON::Validator.validate(json_schema, json)
106
112
  end
107
113
 
108
114
  # Returns the JSON schema for the model.
115
+ #
116
+ # @return [Hash] The JSON schema for the model.
109
117
  def json_schema
110
- @json_schema ||= begin
111
- schema = Builder.new(schema_definition).schema
112
- schema.as_json
113
- end
118
+ @json_schema ||= schema.as_json
114
119
  end
115
120
 
116
- # Define the schema using the provided block.
121
+ # Define the schema for the model using the provided block.
122
+ #
123
+ # @yield The block to define the schema.
124
+ # @raise [ArgumentError] If the class does not have a name.
117
125
  def define_schema(&block)
118
126
  raise ArgumentError, 'The class must have a name' unless name.present?
119
127
 
@@ -121,9 +129,22 @@ module EasyTalk
121
129
  @schema_definition.instance_eval(&block)
122
130
  end
123
131
 
132
+ # Returns the unvalidated schema definition for the model.
133
+ #
134
+ # @return [SchemaDefinition] The unvalidated schema definition for the model.
124
135
  def schema_definition
125
136
  @schema_definition ||= {}
126
137
  end
138
+
139
+ private
140
+
141
+ # Builds the schema using the provided schema definition.
142
+ #
143
+ # @param schema_definition [SchemaDefinition] The schema definition.
144
+ # @return [Schema] The validated schema.
145
+ def build_schema(schema_definition)
146
+ Builders::ObjectBuilder.new(schema_definition).build
147
+ end
127
148
  end
128
149
  end
129
150
  end
@@ -17,6 +17,16 @@ require_relative 'builders/union_builder'
17
17
 
18
18
  # frozen_string_literal: true
19
19
 
20
+ # EasyTalk module provides classes for building JSON schema properties.
21
+ #
22
+ # This module contains the `Property` class, which is used to build a JSON schema property.
23
+ # It also defines a constant `TYPE_TO_BUILDER` which maps property types to their respective builders.
24
+ #
25
+ # Example usage:
26
+ # property = EasyTalk::Property.new(:name, 'String', minLength: 3, maxLength: 50)
27
+ # property.build
28
+ #
29
+ # @see EasyTalk::Property
20
30
  module EasyTalk
21
31
  # Property class for building a JSON schema property.
22
32
  class Property
@@ -56,23 +66,36 @@ module EasyTalk
56
66
  raise ArgumentError, 'property type is missing' if type.blank?
57
67
  end
58
68
 
69
+ # Builds the property based on the specified type, constraints, and builder.
70
+ #
71
+ # If the type responds to the `schema` method, it returns the schema of the type.
72
+ # Otherwise, it returns 'object'.
73
+ #
74
+ # If a builder is specified, it uses the builder to build the property.
75
+ # The arguments passed to the builder depend on whether the builder is a collection type or not.
76
+ #
77
+ # @return [Object] The built property.
59
78
  def build
60
- if type.is_a?(T::Types::Simple)
61
- @type = type.raw_type
62
- return self
63
- end
79
+ return type.respond_to?(:schema) ? type.schema : 'object' unless builder
64
80
 
65
- if builder
66
- builder.new(name, type, constraints).build
67
- else
68
- type.respond_to?(:schema) ? type.schema : 'object'
69
- end
81
+ args = builder.collection_type? ? [name, type, constraints] : [name, constraints]
82
+ builder.new(*args).build
70
83
  end
71
84
 
85
+ # Converts the object to a JSON representation.
86
+ #
87
+ # @param _args [Array] Optional arguments
88
+ # @return [Hash] The JSON representation of the object
72
89
  def as_json(*_args)
73
90
  build.as_json
74
91
  end
75
92
 
93
+ # Returns the builder associated with the property type.
94
+ #
95
+ # The builder is responsible for constructing the property based on its type.
96
+ # It looks up the builder based on the type's class name or name.
97
+ #
98
+ # @return [Builder] The builder associated with the property type.
76
99
  def builder
77
100
  TYPE_TO_BUILDER[type.class.name.to_s] || TYPE_TO_BUILDER[type.name.to_s]
78
101
  end
@@ -1,6 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EasyTalk
2
4
  module Tools
5
+ # FunctionBuilder is a module that builds a hash with the function type and function details.
6
+ # The return value is typically passed as argument to LLM function calling APIs.
3
7
  module FunctionBuilder
8
+ # Creates a new function object based on the given model.
9
+ #
10
+ # @param [Model] model The EasyTalk model containing the function details.
11
+ # @return [Hash] The function object.
4
12
  def self.new(model)
5
13
  {
6
14
  type: 'function',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyTalk
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.8'
5
5
  end
data/lib/easy_talk.rb CHANGED
@@ -9,7 +9,6 @@ module EasyTalk
9
9
  require 'easy_talk/types/all_of'
10
10
  require 'easy_talk/types/one_of'
11
11
  require 'easy_talk/model'
12
- require 'easy_talk/builder'
13
12
  require 'easy_talk/property'
14
13
  require 'easy_talk/schema_definition'
15
14
  require 'easy_talk/tools/function_builder'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_talk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Bayona
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-16 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.10.1
61
+ version: '3.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.10.1
68
+ version: '3.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,90 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-json_expectations
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-mocks
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.13'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.13'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.21'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.21'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.6'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.6'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.29'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.29'
83
167
  description: Generate json-schema from plain Ruby classes.
84
168
  email:
85
169
  - bayona.sergio@gmail.com
@@ -93,13 +177,12 @@ files:
93
177
  - LICENSE.txt
94
178
  - README.md
95
179
  - Rakefile
96
- - easy_talk.gemspec
97
180
  - lib/easy_talk.rb
98
- - lib/easy_talk/builder.rb
99
181
  - lib/easy_talk/builders/all_of_builder.rb
100
182
  - lib/easy_talk/builders/any_of_builder.rb
101
183
  - lib/easy_talk/builders/base_builder.rb
102
184
  - lib/easy_talk/builders/boolean_builder.rb
185
+ - lib/easy_talk/builders/collection_helpers.rb
103
186
  - lib/easy_talk/builders/composition_builder.rb
104
187
  - lib/easy_talk/builders/date_builder.rb
105
188
  - lib/easy_talk/builders/datetime_builder.rb
@@ -108,7 +191,6 @@ files:
108
191
  - lib/easy_talk/builders/number_builder.rb
109
192
  - lib/easy_talk/builders/object_builder.rb
110
193
  - lib/easy_talk/builders/one_of_builder.rb
111
- - lib/easy_talk/builders/ref_array_builder.rb
112
194
  - lib/easy_talk/builders/string_builder.rb
113
195
  - lib/easy_talk/builders/time_builder.rb
114
196
  - lib/easy_talk/builders/typed_array_builder.rb
@@ -147,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
229
  - !ruby/object:Gem::Version
148
230
  version: '0'
149
231
  requirements: []
150
- rubygems_version: 3.5.3
232
+ rubygems_version: 3.5.9
151
233
  signing_key:
152
234
  specification_version: 4
153
235
  summary: Generate json-schema from Ruby classes.
data/easy_talk.gemspec DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/easy_talk/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'easy_talk'
7
- spec.version = EasyTalk::VERSION
8
- spec.authors = ['Sergio Bayona']
9
- spec.email = ['bayona.sergio@gmail.com']
10
-
11
- spec.summary = 'Generate json-schema from Ruby classes.'
12
- spec.description = 'Generate json-schema from plain Ruby classes.'
13
- spec.homepage = 'https://github.com/sergiobayona/easy_talk'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 3.2'
16
-
17
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
-
19
- spec.metadata['homepage_uri'] = spec.homepage
20
- spec.metadata['source_code_uri'] = 'https://github.com/sergiobayona/easy_talk'
21
- spec.metadata['changelog_uri'] = 'https://github.com/sergiobayona/easy_talk/blob/main/CHANGELOG.md'
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (File.expand_path(f) == __FILE__) ||
28
- f.start_with?(*%w[bin/ spec/ .git .github Gemfile])
29
- end
30
- end
31
-
32
- spec.require_paths = ['lib']
33
-
34
- spec.add_dependency 'activesupport', '~> 7.0'
35
- spec.add_dependency 'json-schema', '~> 4'
36
- spec.add_dependency 'sorbet-runtime', '~> 0.5'
37
- spec.add_development_dependency 'pry-byebug', '>= 3.10.1'
38
- spec.add_development_dependency 'rake', '~> 13.1'
39
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'property'
4
- require_relative 'builders/object_builder'
5
-
6
- module EasyTalk
7
- # The Builder class is responsible for building a schema for a class.
8
- class Builder
9
- extend T::Sig
10
-
11
- sig { params(schema_definition: SchemaDefinition).void }
12
- # Initializes a new instance of the Builder class.
13
- #
14
- # @param schema_definition [SchemaDefinition] The schema definition.
15
- def initialize(schema_definition)
16
- @schema_definition = schema_definition
17
- end
18
-
19
- sig { returns(Hash) }
20
- # Retrieves the schema document.
21
- #
22
- # @return [Hash] The schema document.
23
- def schema
24
- @schema = schema_document
25
- end
26
-
27
- sig { returns(String) }
28
- # Returns the JSON representation of the schema document.
29
- #
30
- # @return [String] The JSON schema.
31
- def json_schema
32
- @json_schema ||= schema_document.to_json
33
- end
34
-
35
- sig { returns(Hash) }
36
- # Returns the schema document, building it if necessary.
37
- #
38
- # @return [Hash] The schema document.
39
- def schema_document
40
- @schema_document ||= build_schema
41
- end
42
-
43
- sig { returns(Hash) }
44
- # Builds the schema using the schema definition.
45
- #
46
- # Returns the built schema.
47
- def build_schema
48
- Builders::ObjectBuilder.new(@schema_definition).build
49
- end
50
- end
51
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base_builder'
4
-
5
- module EasyTalk
6
- module Builders
7
- # Builder class for array properties.
8
- class RefArrayBuilder < BaseBuilder
9
- # Initializes a new instance of the ArrayBuilder class.
10
- sig { params(name: Symbol).void }
11
- def initialize(name)
12
- super(name, { type: 'array' }, options, {})
13
- end
14
-
15
- private
16
-
17
- sig { void }
18
- # Updates the option types for the array builder.
19
- def update_option_types
20
- VALID_OPTIONS[:enum][:type] = T::Array[@inner_type]
21
- VALID_OPTIONS[:const][:type] = T::Array[@inner_type]
22
- end
23
- end
24
- end
25
- end