validator_fn 0.4.0 → 0.6.0

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: 1ae4f194cce16e854dccde3dc29e7d382084289945402ded960414d94dc7630f
4
- data.tar.gz: 7a19354da9723c01d81d79540a358dad546a2611b7893399ea38b09025d83f0e
3
+ metadata.gz: 1a96b743aac1f8debf772342d13292a4a211e77a8bc80f90bbe2322de41baf36
4
+ data.tar.gz: de19f5140d49175c360685820c14fb09da3111923b4043a521cdf579543564dd
5
5
  SHA512:
6
- metadata.gz: 452a5fa550d3c5c9948099e1c9e2e840dd800bed22a0b8b777a81c824cdc04d0ea11f496d601fb61b750542585e96741f55292c5bbdf078e499f73b15a961c5b
7
- data.tar.gz: c2d9d6f854407f958024efe80095490ff7d1c890ee4421f02fc5e26ee44a766c26c3e496bc996fecbe1ec4140f97e3e9a9465df6ef14faf69035ba3a1ab569dd
6
+ metadata.gz: 68b01ad9de314a04de20033c6af9d8a11d6ab550c8bdd4aae6d4cd6badebd3f99a93d3c80e33ebee8c1a014db8b174f9714c4bccbc0c362d961afa668f35a957
7
+ data.tar.gz: 554ef0c5ac6308d9be1fc6a26ff7e117e9883a35af1a394b658e646e011e2c376a9dc9b38f17de3e35844fc1f7d2a7668b2ae7c5001080dfe5b396de246efb1e
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.6.0] - 2024-12-19
11
+
12
+ ### Added
13
+ - Added `context` method to ValidatorFn module for scoped evaluation
14
+ - Allows using ValidatorFn methods directly within a block without module prefix
15
+ - Provides isolated environment that doesn't pollute caller's namespace
16
+ - Similar to FnReader's context method but scoped to ValidatorFn
17
+
18
+ ### Changed
19
+ - Updated fn_reader declaration to include the new context method
20
+
21
+ ## [0.5.0] - Previous Release
22
+
23
+ ### Added
24
+ - Enhanced validation capabilities
25
+ - Improved error handling and messaging
26
+ - Support for complex nested structures
27
+
28
+ ## [0.4.0] - Previous Release
29
+
30
+ ### Added
31
+ - Core validation functions
32
+ - Hash and array validation
33
+ - Type checking utilities
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validator_fn (0.4.0)
4
+ validator_fn (0.6.0)
5
5
  fn_reader
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  coderay (1.1.3)
11
11
  diff-lcs (1.4.4)
12
- fn_reader (0.2.0)
12
+ fn_reader (0.2.1)
13
13
  method_source (0.9.2)
14
14
  pry (0.12.2)
15
15
  coderay (~> 1.1.0)
data/README.md CHANGED
@@ -97,7 +97,7 @@ This makes it very useful for processing JSON payloads.
97
97
  You can generate validator code from existing structure:
98
98
 
99
99
  ```ruby
100
- require 'openuri'
100
+ require 'open-uri'
101
101
  require "json"
102
102
  struct = JSON.parse(URI.open("https://api.github.com/users/defunkt").read)
103
103
 
@@ -1,3 +1,3 @@
1
1
  module ValidatorFn
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/validator_fn.rb CHANGED
@@ -4,7 +4,13 @@ require "fn_reader"
4
4
 
5
5
  module ValidatorFn
6
6
  fn_reader :something, :matches, :either, :array_of, :any, :is_nil,
7
- :maybe, :present, :is_a, :is_a_bool, :int, :hash_of, :invalid, :generate_validator, :handle_error, :error_str, :apply
7
+ :maybe, :present, :is_a, :is_a_bool, :int, :hash_of, :invalid, :generate_validator, :handle_error, :error_str, :apply, :enum_of, :context
8
+
9
+ def self.context(&caller)
10
+ extended = Object.new
11
+ extended.extend ValidatorFn
12
+ extended.instance_eval(&caller)
13
+ end
8
14
 
9
15
  @@apply = ->fn, a {
10
16
  begin
@@ -24,6 +30,10 @@ module ValidatorFn
24
30
  end
25
31
  value
26
32
  }.curry
33
+ @@enum_of = ->enum, a {
34
+ raise Error.new("Should be in #{enum.join(",")}") unless enum.include?(a)
35
+ a
36
+ }.curry
27
37
  @@array_of = ->fn, array {
28
38
  is_a.(Array).(array)
29
39
  array.each_with_index.map do |a, idx|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validator_fn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Chabot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-04 00:00:00.000000000 Z
11
+ date: 2025-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fn_reader
@@ -34,6 +34,7 @@ files:
34
34
  - ".gitignore"
35
35
  - ".rspec"
36
36
  - ".travis.yml"
37
+ - CHANGELOG.md
37
38
  - CODE_OF_CONDUCT.md
38
39
  - Gemfile
39
40
  - Gemfile.lock
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  requirements: []
70
- rubygems_version: 3.4.12
71
+ rubygems_version: 3.3.22
71
72
  signing_key:
72
73
  specification_version: 4
73
74
  summary: Series of lambdas for validating Ruby structures