active_fields 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -1
  3. data/README.md +633 -0
  4. data/app/models/active_fields/field/boolean.rb +10 -3
  5. data/app/models/active_fields/field/date.rb +10 -4
  6. data/app/models/active_fields/field/date_array.rb +12 -18
  7. data/app/models/active_fields/field/date_time.rb +77 -0
  8. data/app/models/active_fields/field/date_time_array.rb +61 -0
  9. data/app/models/active_fields/field/decimal.rb +35 -6
  10. data/app/models/active_fields/field/decimal_array.rb +28 -11
  11. data/app/models/active_fields/field/enum.rb +28 -9
  12. data/app/models/active_fields/field/enum_array.rb +29 -22
  13. data/app/models/active_fields/field/integer.rb +10 -4
  14. data/app/models/active_fields/field/integer_array.rb +12 -8
  15. data/app/models/active_fields/field/text.rb +10 -4
  16. data/app/models/active_fields/field/text_array.rb +14 -8
  17. data/app/models/concerns/active_fields/customizable_concern.rb +60 -51
  18. data/app/models/concerns/active_fields/field_array_concern.rb +25 -0
  19. data/app/models/concerns/active_fields/field_concern.rb +45 -24
  20. data/app/models/concerns/active_fields/value_concern.rb +32 -4
  21. data/db/migrate/20240229230000_create_active_fields_tables.rb +2 -2
  22. data/lib/active_fields/casters/base_caster.rb +8 -2
  23. data/lib/active_fields/casters/date_caster.rb +8 -6
  24. data/lib/active_fields/casters/date_time_array_caster.rb +19 -0
  25. data/lib/active_fields/casters/date_time_caster.rb +43 -0
  26. data/lib/active_fields/casters/decimal_caster.rb +10 -2
  27. data/lib/active_fields/casters/enum_array_caster.rb +13 -1
  28. data/lib/active_fields/casters/enum_caster.rb +15 -1
  29. data/lib/active_fields/casters/integer_caster.rb +2 -2
  30. data/lib/active_fields/config.rb +12 -1
  31. data/lib/active_fields/customizable_config.rb +1 -1
  32. data/lib/active_fields/has_active_fields.rb +1 -1
  33. data/lib/active_fields/validators/base_validator.rb +7 -3
  34. data/lib/active_fields/validators/boolean_validator.rb +2 -2
  35. data/lib/active_fields/validators/date_array_validator.rb +3 -3
  36. data/lib/active_fields/validators/date_time_array_validator.rb +26 -0
  37. data/lib/active_fields/validators/date_time_validator.rb +19 -0
  38. data/lib/active_fields/validators/date_validator.rb +3 -3
  39. data/lib/active_fields/validators/decimal_array_validator.rb +2 -2
  40. data/lib/active_fields/validators/decimal_validator.rb +2 -2
  41. data/lib/active_fields/validators/enum_array_validator.rb +3 -3
  42. data/lib/active_fields/validators/enum_validator.rb +3 -3
  43. data/lib/active_fields/validators/integer_array_validator.rb +2 -2
  44. data/lib/active_fields/validators/integer_validator.rb +2 -2
  45. data/lib/active_fields/validators/text_array_validator.rb +2 -2
  46. data/lib/active_fields/validators/text_validator.rb +2 -2
  47. data/lib/active_fields/version.rb +1 -1
  48. data/lib/active_fields.rb +4 -0
  49. data/lib/generators/active_fields/install/USAGE +5 -0
  50. data/lib/generators/active_fields/install/install_generator.rb +29 -0
  51. metadata +11 -16
@@ -11,11 +11,11 @@ module ActiveFields
11
11
  return
12
12
  end
13
13
 
14
- validate_size(value, min: active_field.min_size, max: active_field.max_size)
14
+ validate_size(value, min: options[:min_size], max: options[:max_size])
15
15
 
16
16
  value.each do |elem_value|
17
- if elem_value.is_a?(Date)
18
- validate_minmax(elem_value, min: active_field.min, max: active_field.max)
17
+ if elem_value.acts_like?(:date)
18
+ validate_minmax(elem_value, min: options[:min], max: options[:max])
19
19
  else
20
20
  errors << :invalid
21
21
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFields
4
+ module Validators
5
+ class DateTimeArrayValidator < BaseValidator
6
+ private
7
+
8
+ def perform_validation(value)
9
+ unless value.is_a?(Array)
10
+ errors << :invalid
11
+ return
12
+ end
13
+
14
+ validate_size(value, min: options[:min_size], max: options[:max_size])
15
+
16
+ value.each do |elem_value|
17
+ if elem_value.acts_like?(:time)
18
+ validate_minmax(elem_value, min: options[:min], max: options[:max])
19
+ else
20
+ errors << :invalid
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFields
4
+ module Validators
5
+ class DateTimeValidator < BaseValidator
6
+ private
7
+
8
+ def perform_validation(value)
9
+ if value.nil?
10
+ errors << :required if options[:required]
11
+ elsif value.acts_like?(:time)
12
+ validate_minmax(value, min: options[:min], max: options[:max])
13
+ else
14
+ errors << :invalid
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,9 +7,9 @@ module ActiveFields
7
7
 
8
8
  def perform_validation(value)
9
9
  if value.nil?
10
- errors << :required if active_field.required?
11
- elsif value.is_a?(Date)
12
- validate_minmax(value, min: active_field.min, max: active_field.max)
10
+ errors << :required if options[:required]
11
+ elsif value.acts_like?(:date)
12
+ validate_minmax(value, min: options[:min], max: options[:max])
13
13
  else
14
14
  errors << :invalid
15
15
  end
@@ -11,11 +11,11 @@ module ActiveFields
11
11
  return
12
12
  end
13
13
 
14
- validate_size(value, min: active_field.min_size, max: active_field.max_size)
14
+ validate_size(value, min: options[:min_size], max: options[:max_size])
15
15
 
16
16
  value.each do |elem_value|
17
17
  if elem_value.is_a?(Numeric)
18
- validate_minmax(elem_value, min: active_field.min, max: active_field.max)
18
+ validate_minmax(elem_value, min: options[:min], max: options[:max])
19
19
  else
20
20
  errors << :invalid
21
21
  end
@@ -7,9 +7,9 @@ module ActiveFields
7
7
 
8
8
  def perform_validation(value)
9
9
  if value.nil?
10
- errors << :required if active_field.required?
10
+ errors << :required if options[:required]
11
11
  elsif value.is_a?(Numeric)
12
- validate_minmax(value, min: active_field.min, max: active_field.max)
12
+ validate_minmax(value, min: options[:min], max: options[:max])
13
13
  else
14
14
  errors << :invalid
15
15
  end
@@ -11,11 +11,11 @@ module ActiveFields
11
11
  return
12
12
  end
13
13
 
14
- validate_size(value, min: active_field.min_size, max: active_field.max_size)
14
+ validate_size(value, min: options[:min_size], max: options[:max_size])
15
15
 
16
- if active_field.allowed_values.is_a?(Array)
16
+ if options[:allowed_values].is_a?(Array)
17
17
  value.each do |elem_value|
18
- validate_value_allowed(elem_value, allowed_values: active_field.allowed_values)
18
+ validate_value_allowed(elem_value, allowed_values: options[:allowed_values])
19
19
  end
20
20
  end
21
21
 
@@ -7,9 +7,9 @@ module ActiveFields
7
7
 
8
8
  def perform_validation(value)
9
9
  if value.nil?
10
- errors << :required if active_field.required?
11
- elsif active_field.allowed_values.is_a?(Array)
12
- validate_value_allowed(value, allowed_values: active_field.allowed_values)
10
+ errors << :required if options[:required]
11
+ elsif options[:allowed_values].is_a?(Array)
12
+ validate_value_allowed(value, allowed_values: options[:allowed_values])
13
13
  end
14
14
  end
15
15
 
@@ -11,11 +11,11 @@ module ActiveFields
11
11
  return
12
12
  end
13
13
 
14
- validate_size(value, min: active_field.min_size, max: active_field.max_size)
14
+ validate_size(value, min: options[:min_size], max: options[:max_size])
15
15
 
16
16
  value.each do |elem_value|
17
17
  if elem_value.is_a?(Numeric)
18
- validate_minmax(elem_value, min: active_field.min, max: active_field.max)
18
+ validate_minmax(elem_value, min: options[:min], max: options[:max])
19
19
  else
20
20
  errors << :invalid
21
21
  end
@@ -7,9 +7,9 @@ module ActiveFields
7
7
 
8
8
  def perform_validation(value)
9
9
  if value.nil?
10
- errors << :required if active_field.required?
10
+ errors << :required if options[:required]
11
11
  elsif value.is_a?(Numeric)
12
- validate_minmax(value, min: active_field.min, max: active_field.max)
12
+ validate_minmax(value, min: options[:min], max: options[:max])
13
13
  else
14
14
  errors << :invalid
15
15
  end
@@ -11,11 +11,11 @@ module ActiveFields
11
11
  return
12
12
  end
13
13
 
14
- validate_size(value, min: active_field.min_size, max: active_field.max_size)
14
+ validate_size(value, min: options[:min_size], max: options[:max_size])
15
15
 
16
16
  value.each do |elem_value|
17
17
  if elem_value.is_a?(String)
18
- validate_length(elem_value, min: active_field.min_length, max: active_field.max_length)
18
+ validate_length(elem_value, min: options[:min_length], max: options[:max_length])
19
19
  else
20
20
  errors << :invalid
21
21
  end
@@ -7,9 +7,9 @@ module ActiveFields
7
7
 
8
8
  def perform_validation(value)
9
9
  if value.nil?
10
- errors << :required if active_field.required?
10
+ errors << :required if options[:required]
11
11
  elsif value.is_a?(String)
12
- validate_length(value, min: active_field.min_length, max: active_field.max_length)
12
+ validate_length(value, min: options[:min_length], max: options[:max_length])
13
13
  else
14
14
  errors << :invalid
15
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveFields
4
- VERSION = "0.2.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/active_fields.rb CHANGED
@@ -13,6 +13,8 @@ module ActiveFields
13
13
  autoload :BooleanCaster, "active_fields/casters/boolean_caster"
14
14
  autoload :DateCaster, "active_fields/casters/date_caster"
15
15
  autoload :DateArrayCaster, "active_fields/casters/date_array_caster"
16
+ autoload :DateTimeCaster, "active_fields/casters/date_time_caster"
17
+ autoload :DateTimeArrayCaster, "active_fields/casters/date_time_array_caster"
16
18
  autoload :DecimalCaster, "active_fields/casters/decimal_caster"
17
19
  autoload :DecimalArrayCaster, "active_fields/casters/decimal_array_caster"
18
20
  autoload :EnumCaster, "active_fields/casters/enum_caster"
@@ -28,6 +30,8 @@ module ActiveFields
28
30
  autoload :BooleanValidator, "active_fields/validators/boolean_validator"
29
31
  autoload :DateValidator, "active_fields/validators/date_validator"
30
32
  autoload :DateArrayValidator, "active_fields/validators/date_array_validator"
33
+ autoload :DateTimeValidator, "active_fields/validators/date_time_validator"
34
+ autoload :DateTimeArrayValidator, "active_fields/validators/date_time_array_validator"
31
35
  autoload :DecimalValidator, "active_fields/validators/decimal_validator"
32
36
  autoload :DecimalArrayValidator, "active_fields/validators/decimal_array_validator"
33
37
  autoload :EnumValidator, "active_fields/validators/enum_validator"
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Generates an initializer and copies plugin migrations.
3
+
4
+ Examples:
5
+ `bin/rails generate active_fields:install`
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module ActiveFields
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ desc "This generator creates an create_initializer and copies plugin migrations"
9
+
10
+ def create_initializer
11
+ initializer "active_fields.rb", <<~RUBY
12
+ ActiveFields.configure do |config|
13
+ # Change fields base class:
14
+ # config.field_base_class_name = "CustomField"
15
+ # Change value class:
16
+ # config.value_class_name = "CustomValue"
17
+
18
+ # Register custom field type:
19
+ # config.register_field :ip, "IpField"
20
+ end
21
+ RUBY
22
+ end
23
+
24
+ def install_migrations
25
+ rails_command "active_fields:install:migrations"
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Usanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-06-13 00:00:00.000000000 Z
12
+ date: 2024-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: puma
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: rake
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -225,6 +211,8 @@ files:
225
211
  - app/models/active_fields/field/boolean.rb
226
212
  - app/models/active_fields/field/date.rb
227
213
  - app/models/active_fields/field/date_array.rb
214
+ - app/models/active_fields/field/date_time.rb
215
+ - app/models/active_fields/field/date_time_array.rb
228
216
  - app/models/active_fields/field/decimal.rb
229
217
  - app/models/active_fields/field/decimal_array.rb
230
218
  - app/models/active_fields/field/enum.rb
@@ -235,6 +223,7 @@ files:
235
223
  - app/models/active_fields/field/text_array.rb
236
224
  - app/models/active_fields/value.rb
237
225
  - app/models/concerns/active_fields/customizable_concern.rb
226
+ - app/models/concerns/active_fields/field_array_concern.rb
238
227
  - app/models/concerns/active_fields/field_concern.rb
239
228
  - app/models/concerns/active_fields/value_concern.rb
240
229
  - config/routes.rb
@@ -244,6 +233,8 @@ files:
244
233
  - lib/active_fields/casters/boolean_caster.rb
245
234
  - lib/active_fields/casters/date_array_caster.rb
246
235
  - lib/active_fields/casters/date_caster.rb
236
+ - lib/active_fields/casters/date_time_array_caster.rb
237
+ - lib/active_fields/casters/date_time_caster.rb
247
238
  - lib/active_fields/casters/decimal_array_caster.rb
248
239
  - lib/active_fields/casters/decimal_caster.rb
249
240
  - lib/active_fields/casters/enum_array_caster.rb
@@ -259,6 +250,8 @@ files:
259
250
  - lib/active_fields/validators/base_validator.rb
260
251
  - lib/active_fields/validators/boolean_validator.rb
261
252
  - lib/active_fields/validators/date_array_validator.rb
253
+ - lib/active_fields/validators/date_time_array_validator.rb
254
+ - lib/active_fields/validators/date_time_validator.rb
262
255
  - lib/active_fields/validators/date_validator.rb
263
256
  - lib/active_fields/validators/decimal_array_validator.rb
264
257
  - lib/active_fields/validators/decimal_validator.rb
@@ -269,6 +262,8 @@ files:
269
262
  - lib/active_fields/validators/text_array_validator.rb
270
263
  - lib/active_fields/validators/text_validator.rb
271
264
  - lib/active_fields/version.rb
265
+ - lib/generators/active_fields/install/USAGE
266
+ - lib/generators/active_fields/install/install_generator.rb
272
267
  - lib/tasks/active_fields_tasks.rake
273
268
  - sig/active_fields.rbs
274
269
  homepage: https://github.com/lassoid/active_fields