rospatent 1.5.0 → 1.5.1

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: 4a3938079b33ac5c291c85501df526ec12b7721a91c9f7c9a4b5c35c56a8fdab
4
- data.tar.gz: 2a8cb80112a1c0380f2dd15f2e3e4909ae37f84e7ef3a819aa9d86fce6d1e765
3
+ metadata.gz: 886b7fc58ff9c0baec9e8e9d538d751e2d6b5f8aea24c0b144dd9d922a8128ca
4
+ data.tar.gz: 953a7ca14bda74da201f12b11a4006119ab3388a0165fec32d52493f7320cd0f
5
5
  SHA512:
6
- metadata.gz: 8843ca4bd8c87de711bed059c9f315a8d46a6123c0763a3eb7dcbfc5af6512e1d35b03782a22b37eb74578942592cb699b4ab8eb07c7744f651230b950c03e41
7
- data.tar.gz: 29896e1b71030d368a54fc4d40bc3a9cd79318b82089618f71e98eafee65ce266d781dd2d1518001e0bd388af0937f2d46a5c7f911673d155738fa61e48fda44
6
+ metadata.gz: 696194b474592192c22818c2eb57ff515fdd92d67aa72d4bf2f5d8f0b51a3a62f5a758e7e5def7561a71da90c8c13c56ea92e845f724096e1443fa5155aaa7b4
7
+ data.tar.gz: d00b71f8a0822cef0682913ddea29d1e8b564f38c983d7562a32fe185e40cfea904f56106ceb6c2f0e39d7a2ab10395fc52f993845cf55757a5c2dadb5846e46
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.5.1] - 2026-05-09
9
+
10
+ ### Fixed
11
+ - **Partial `validation_limits` assignment overwrote defaults**: Setting `config.validation_limits = { query_max_length: 5000 }` in a Rails initializer (or anywhere else) used to replace the entire hash, leaving the other 16 keys `nil` and breaking validators downstream (e.g. `validate_positive_integer(..., max_value: nil)` for `limit_max_value`, `offset_max_value`, etc.). The writer now merges the supplied hash into the defaults, so omitted keys keep their default values.
12
+ - **Unknown `validation_limits` keys silently ignored**: Misspelled or unsupported keys used to be accepted and stored without effect. Assignment now raises `ArgumentError` listing the offending keys, surfacing typos at boot time.
13
+
14
+ ### Changed
15
+ - Extracted `Rospatent::Configuration::DEFAULT_VALIDATION_LIMITS` as a frozen public constant — single source of truth for default limits, referenced by `reset!`, the merging writer, and tests.
16
+ - Updated the Rails install generator template (`lib/generators/rospatent/install/templates/initializer.rb`) with a commented `validation_limits` example documenting the merge semantics.
17
+
8
18
  ## [1.5.0] - 2025-06-09
9
19
 
10
20
  ### Added
@@ -45,4 +45,9 @@ Rospatent.configure do |config|
45
45
  # config.cache_ttl = ENV.fetch("ROSPATENT_CACHE_TTL", "300").to_i
46
46
  # config.cache_max_size = ENV.fetch("ROSPATENT_CACHE_MAX_SIZE", "1000").to_i
47
47
  # config.connection_pool_size = ENV.fetch("ROSPATENT_POOL_SIZE", "5").to_i
48
+
49
+ # Optional: Override one or more validation limits.
50
+ # Assignment merges into defaults — keys you omit keep their default values.
51
+ # Unknown keys raise ArgumentError. See Rospatent::Configuration::DEFAULT_VALIDATION_LIMITS.
52
+ # config.validation_limits = { query_max_length: 5000, similar_text_max_length: 20_000 }
48
53
  end
@@ -7,6 +7,28 @@ module Rospatent
7
7
  class Configuration
8
8
  ENVIRONMENTS = %w[development staging production].freeze
9
9
 
10
+ # Default validation limits applied to all configurations.
11
+ # Partial overrides via {#validation_limits=} are merged into these defaults.
12
+ DEFAULT_VALIDATION_LIMITS = {
13
+ query_max_length: 2000,
14
+ natural_query_max_length: 2000,
15
+ limit_max_value: 100,
16
+ offset_max_value: 10_000,
17
+ array_max_size: 10,
18
+ string_max_length: 1000,
19
+ pre_tag_max_length: 50,
20
+ post_tag_max_length: 50,
21
+ pre_tag_max_size: 10,
22
+ post_tag_max_size: 10,
23
+ classification_query_max_length: 1000,
24
+ classification_code_max_length: 50,
25
+ similar_text_min_words: 50,
26
+ similar_text_max_length: 10_000,
27
+ similar_count_max_value: 1000,
28
+ batch_size_max_value: 50,
29
+ batch_ids_max_size: 1000
30
+ }.freeze
31
+
10
32
  # Base URL for the Rospatent API
11
33
  attr_accessor :api_url
12
34
  # JWT token for authentication
@@ -27,8 +49,8 @@ module Rospatent
27
49
  attr_accessor :token_expires_at, :token_refresh_callback
28
50
  # Connection pooling
29
51
  attr_accessor :connection_pool_size, :connection_keep_alive
30
- # Validation limits
31
- attr_accessor :validation_limits
52
+ # Validation limits — readable as a hash; assignment merges into defaults.
53
+ attr_reader :validation_limits
32
54
 
33
55
  # Initialize a new configuration with default values
34
56
  def initialize
@@ -59,26 +81,8 @@ module Rospatent
59
81
  @connection_pool_size = ENV.fetch("ROSPATENT_POOL_SIZE", "5").to_i
60
82
  @connection_keep_alive = ENV.fetch("ROSPATENT_KEEP_ALIVE", "true") == "true"
61
83
 
62
- # Validation limits
63
- @validation_limits = {
64
- query_max_length: 2000,
65
- natural_query_max_length: 2000,
66
- limit_max_value: 100,
67
- offset_max_value: 10_000,
68
- array_max_size: 10,
69
- string_max_length: 1000,
70
- pre_tag_max_length: 50,
71
- post_tag_max_length: 50,
72
- pre_tag_max_size: 10,
73
- post_tag_max_size: 10,
74
- classification_query_max_length: 1000,
75
- classification_code_max_length: 50,
76
- similar_text_min_words: 50,
77
- similar_text_max_length: 10_000,
78
- similar_count_max_value: 1000,
79
- batch_size_max_value: 50,
80
- batch_ids_max_size: 1000
81
- }
84
+ # Validation limits — start from defaults; partial overrides merge in.
85
+ @validation_limits = DEFAULT_VALIDATION_LIMITS.dup
82
86
 
83
87
  load_environment_config
84
88
  end
@@ -126,6 +130,26 @@ module Rospatent
126
130
  end
127
131
  end
128
132
 
133
+ # Merge a partial validation_limits hash into the defaults.
134
+ # Assigning a hash that omits some keys keeps the default value for those keys
135
+ # rather than dropping them, which would break validators downstream.
136
+ # @param values [Hash] Subset (or full set) of validation limit overrides
137
+ # @raise [ArgumentError] If the value is not a Hash or contains unknown keys
138
+ def validation_limits=(values)
139
+ unless values.is_a?(Hash)
140
+ raise ArgumentError, "validation_limits must be a Hash, got #{values.class}"
141
+ end
142
+
143
+ unknown = values.keys - DEFAULT_VALIDATION_LIMITS.keys
144
+ unless unknown.empty?
145
+ raise ArgumentError,
146
+ "Unknown validation_limits keys: #{unknown.inspect}. " \
147
+ "Allowed: #{DEFAULT_VALIDATION_LIMITS.keys.inspect}"
148
+ end
149
+
150
+ @validation_limits = DEFAULT_VALIDATION_LIMITS.merge(values)
151
+ end
152
+
129
153
  private
130
154
 
131
155
  # Load environment-specific configuration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rospatent
4
- VERSION = "1.5.0"
4
+ VERSION = "1.5.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rospatent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandr Dryzhuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-15 00:00:00.000000000 Z
11
+ date: 2026-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday