validify_me 0.1.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 +7 -0
- data/Gemfile +8 -0
- data/README.md +53 -0
- data/Rakefile +4 -0
- data/lib/validify_me/data_validator.rb +73 -0
- data/lib/validify_me/version.rb +5 -0
- data/lib/validify_me.rb +9 -0
- data/sig/validify_me.rbs +4 -0
- data/validify_me.gemspec +35 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80c6d485ff82c68465d08e62090b1f62ec49b1355bc6eb589825b6d0185adea0
|
4
|
+
data.tar.gz: b8765ea0dbafa83e55dd76768aed087e9ef6d3df1cd79be530db30a100b46d35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c472476a0c8f9c918520c6bcd5a38e9d52aa8cc3494a0549c792608f9fdc611a99ee0c4ccb4c1c9044c17f688e9300251aeaace9888312f72de247ef4c2d0668
|
7
|
+
data.tar.gz: 561155958b5ea8ce9dc267c88d8d32bce796ba42bfadf5f9bdad29930b459ff7ce299953787cec41e810790c87a253d2ead41bfd44afde09ca69fd5d738b54fc
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# "ValidifyMe"
|
2
|
+
|
3
|
+
ValidifyMe is a Ruby library that combines validation and serialization functionality, providing a comprehensive solution for managing and processing data in your Ruby applications. It simplifies the task of validating and serializing data by offering a unified and intuitive interface.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- <b>Validation</b>: Perform data validation using customizable rules and constraints. Ensure data integrity and enforce validation rules with ease. <br>
|
8
|
+
- <b>Serialization</b>: Serialize data into various formats, such as JSON, XML, or YAML.
|
9
|
+
Convert Ruby objects into a structured representation for storage or communication purposes.
|
10
|
+
- <b>Flexible Configuration</b>: Customize validation rules and serialization options to suit your specific requirements.
|
11
|
+
- <b>Easy Integration</b>: Seamlessly integrate ValidifyMe into your existing Ruby projects with minimal code changes.
|
12
|
+
- <b>Extensible and Composable</b>: Take advantage of the modular architecture to add your own custom validators and serializers.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add the following line to your Gemfile:
|
17
|
+
|
18
|
+
`gem 'validify_me'`
|
19
|
+
|
20
|
+
Then, run the following command to install the gem:
|
21
|
+
|
22
|
+
`bundle install`
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Here's a simple example demonstrating how to use ValidifyMe for data validation and serialization:
|
27
|
+
|
28
|
+
```
|
29
|
+
require 'validify_me'
|
30
|
+
|
31
|
+
class Person
|
32
|
+
include ValidifyMe::Validatable
|
33
|
+
include ValidifyMe::Serializable
|
34
|
+
|
35
|
+
attr_accessor :name, :age
|
36
|
+
|
37
|
+
validates :name, presence: true
|
38
|
+
validates :age, numericality: { greater_than: 0 }
|
39
|
+
|
40
|
+
serialize_as :json
|
41
|
+
end
|
42
|
+
|
43
|
+
person = Person.new
|
44
|
+
person.name = 'John Doe'
|
45
|
+
person.age = 30
|
46
|
+
|
47
|
+
if person.valid?
|
48
|
+
serialized_data = person.serialize
|
49
|
+
# Perform further operations with the serialized data
|
50
|
+
else
|
51
|
+
puts "Invalid data: #{person.errors}"
|
52
|
+
end
|
53
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module ValidifyMe
|
2
|
+
module DataValidator
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def params(&block)
|
9
|
+
context = Context.new
|
10
|
+
|
11
|
+
return {} unless block_given?
|
12
|
+
|
13
|
+
context.instance_eval(&block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Context
|
18
|
+
attr_reader :params
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@params = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def optional(name)
|
25
|
+
parameter = ParameterDefinition.new(name, {})
|
26
|
+
@params << parameter
|
27
|
+
parameter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ParameterDefinition
|
32
|
+
attr_reader :name, :constraints
|
33
|
+
|
34
|
+
def initialize(name, constraints)
|
35
|
+
@name = name
|
36
|
+
@constraints = constraints
|
37
|
+
end
|
38
|
+
|
39
|
+
def value(type, **options)
|
40
|
+
constraints[:type] = type
|
41
|
+
constraints.merge!(options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# ---------------- Commented for now ----------------
|
46
|
+
# def valid?
|
47
|
+
# errors.empty?
|
48
|
+
# end
|
49
|
+
|
50
|
+
# def errors
|
51
|
+
# @errors ||= Errors.new
|
52
|
+
# end
|
53
|
+
|
54
|
+
# class Errors
|
55
|
+
# def initialize
|
56
|
+
# @errors = {}
|
57
|
+
# end
|
58
|
+
|
59
|
+
# def add(attribute, message)
|
60
|
+
# @errors[attribute] ||= []
|
61
|
+
# @errors[attribute] << message
|
62
|
+
# end
|
63
|
+
|
64
|
+
# def empty?
|
65
|
+
# @errors.empty?
|
66
|
+
# end
|
67
|
+
|
68
|
+
# def to_hash
|
69
|
+
# @errors
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
end
|
73
|
+
end
|
data/lib/validify_me.rb
ADDED
data/sig/validify_me.rbs
ADDED
data/validify_me.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/validify_me/version"
|
4
|
+
require_relative "lib/validify_me/data_validator"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "validify_me"
|
8
|
+
spec.version = ValidifyMe::VERSION
|
9
|
+
spec.authors = ["Jovan"]
|
10
|
+
spec.email = ["jovansr@protonmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Gem for validating and serializing data"
|
13
|
+
spec.homepage = "https://github.com/Ckojo/validify_me"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/Ckojo/validify_me"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, check out our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validify_me
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jovan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- jovansr@protonmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- lib/validify_me.rb
|
24
|
+
- lib/validify_me/data_validator.rb
|
25
|
+
- lib/validify_me/version.rb
|
26
|
+
- sig/validify_me.rbs
|
27
|
+
- validify_me.gemspec
|
28
|
+
homepage: https://github.com/Ckojo/validify_me
|
29
|
+
licenses: []
|
30
|
+
metadata:
|
31
|
+
homepage_uri: https://github.com/Ckojo/validify_me
|
32
|
+
source_code_uri: https://github.com/Ckojo/validify_me
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.6.0
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.3.5
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Gem for validating and serializing data
|
52
|
+
test_files: []
|