active_fields 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +3 -15
- data/CHANGELOG.md +19 -0
- data/README.md +633 -0
- data/Rakefile +7 -0
- data/app/models/active_fields/application_record.rb +7 -0
- data/app/models/active_fields/field/base.rb +17 -0
- data/{lib/active_fields/models → app/models/active_fields}/field/boolean.rb +14 -9
- data/{lib/active_fields/models → app/models/active_fields}/field/date.rb +16 -12
- data/app/models/active_fields/field/date_array.rb +36 -0
- data/app/models/active_fields/field/date_time.rb +77 -0
- data/app/models/active_fields/field/date_time_array.rb +61 -0
- data/app/models/active_fields/field/decimal.rb +75 -0
- data/app/models/active_fields/field/decimal_array.rb +59 -0
- data/{lib/active_fields/models → app/models/active_fields}/field/enum.rb +34 -17
- data/app/models/active_fields/field/enum_array.rb +64 -0
- data/{lib/active_fields/models → app/models/active_fields}/field/integer.rb +16 -12
- data/app/models/active_fields/field/integer_array.rb +36 -0
- data/{lib/active_fields/models → app/models/active_fields}/field/text.rb +16 -12
- data/app/models/active_fields/field/text_array.rb +39 -0
- data/app/models/active_fields/value.rb +15 -0
- data/app/models/concerns/active_fields/customizable_concern.rb +94 -0
- data/app/models/concerns/active_fields/field_array_concern.rb +25 -0
- data/app/models/concerns/active_fields/field_concern.rb +111 -0
- data/app/models/concerns/active_fields/value_concern.rb +83 -0
- data/config/routes.rb +4 -0
- data/{lib/generators/active_fields/install/templates/create_active_fields_tables.rb.tt → db/migrate/20240229230000_create_active_fields_tables.rb} +8 -6
- data/lib/active_fields/casters/base_caster.rb +8 -2
- data/lib/active_fields/casters/boolean_caster.rb +0 -2
- data/lib/active_fields/casters/date_array_caster.rb +0 -2
- data/lib/active_fields/casters/date_caster.rb +8 -8
- data/lib/active_fields/casters/date_time_array_caster.rb +19 -0
- data/lib/active_fields/casters/date_time_caster.rb +43 -0
- data/lib/active_fields/casters/decimal_array_caster.rb +0 -2
- data/lib/active_fields/casters/decimal_caster.rb +10 -4
- data/lib/active_fields/casters/enum_array_caster.rb +13 -3
- data/lib/active_fields/casters/enum_caster.rb +15 -3
- data/lib/active_fields/casters/integer_array_caster.rb +0 -2
- data/lib/active_fields/casters/integer_caster.rb +2 -4
- data/lib/active_fields/casters/text_array_caster.rb +0 -2
- data/lib/active_fields/casters/text_caster.rb +0 -2
- data/lib/active_fields/config.rb +61 -0
- data/lib/active_fields/customizable_config.rb +24 -0
- data/lib/active_fields/engine.rb +13 -0
- data/lib/active_fields/has_active_fields.rb +19 -0
- data/lib/active_fields/validators/base_validator.rb +7 -3
- data/lib/active_fields/validators/boolean_validator.rb +2 -4
- data/lib/active_fields/validators/date_array_validator.rb +3 -5
- data/lib/active_fields/validators/date_time_array_validator.rb +26 -0
- data/lib/active_fields/validators/date_time_validator.rb +19 -0
- data/lib/active_fields/validators/date_validator.rb +3 -5
- data/lib/active_fields/validators/decimal_array_validator.rb +2 -4
- data/lib/active_fields/validators/decimal_validator.rb +2 -4
- data/lib/active_fields/validators/enum_array_validator.rb +3 -5
- data/lib/active_fields/validators/enum_validator.rb +3 -5
- data/lib/active_fields/validators/integer_array_validator.rb +2 -4
- data/lib/active_fields/validators/integer_validator.rb +2 -4
- data/lib/active_fields/validators/text_array_validator.rb +2 -4
- data/lib/active_fields/validators/text_validator.rb +2 -4
- data/lib/active_fields/version.rb +1 -1
- data/lib/active_fields.rb +47 -7
- data/lib/generators/active_fields/install/USAGE +1 -1
- data/lib/generators/active_fields/install/install_generator.rb +14 -18
- data/lib/tasks/active_fields_tasks.rake +6 -0
- metadata +49 -36
- data/lib/active_fields/models/concerns/concern.rb +0 -16
- data/lib/active_fields/models/concerns/customizable.rb +0 -83
- data/lib/active_fields/models/concerns/field_concern.rb +0 -79
- data/lib/active_fields/models/concerns/value_concern.rb +0 -50
- data/lib/active_fields/models/field/date_array.rb +0 -44
- data/lib/active_fields/models/field/decimal.rb +0 -48
- data/lib/active_fields/models/field/decimal_array.rb +0 -44
- data/lib/active_fields/models/field/enum_array.rb +0 -59
- data/lib/active_fields/models/field/integer_array.rb +0 -34
- data/lib/active_fields/models/field/text_array.rb +0 -35
- data/lib/active_fields/models/field.rb +0 -27
- data/lib/active_fields/models/value.rb +0 -30
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../field"
|
4
|
-
|
5
|
-
module ActiveFields
|
6
|
-
class Field
|
7
|
-
class TextArray < ActiveFields::Field
|
8
|
-
store_accessor :options, :min_size, :max_size, :min_length, :max_length
|
9
|
-
|
10
|
-
# attribute :min_size, :integer
|
11
|
-
# attribute :max_size, :integer
|
12
|
-
# attribute :min_length, :integer
|
13
|
-
# attribute :max_length, :integer
|
14
|
-
|
15
|
-
validates :min_size, comparison: { greater_than_or_equal_to: 0 }, allow_nil: true
|
16
|
-
validates :max_size, comparison: { greater_than_or_equal_to: ->(r) { r.min_size || 0 } }, allow_nil: true
|
17
|
-
validates :min_length, comparison: { greater_than_or_equal_to: 0 }, allow_nil: true
|
18
|
-
validates :max_length, comparison: { greater_than_or_equal_to: ->(r) { r.min_length || 0 } }, allow_nil: true
|
19
|
-
|
20
|
-
%i[min_size max_size min_length max_length].each do |column|
|
21
|
-
define_method(column) do
|
22
|
-
ActiveFields::Casters::IntegerCaster.new.deserialize(super())
|
23
|
-
end
|
24
|
-
|
25
|
-
define_method(:"#{column}=") do |other|
|
26
|
-
super(ActiveFields::Casters::IntegerCaster.new.serialize(other))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def set_defaults; end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# == Schema Information
|
4
|
-
#
|
5
|
-
# Table name: active_fields
|
6
|
-
#
|
7
|
-
# id :bigint not null, primary key
|
8
|
-
# customizable_type :string not null
|
9
|
-
# default_value :jsonb
|
10
|
-
# name :string not null
|
11
|
-
# options :jsonb default({}), not null
|
12
|
-
# type :string not null
|
13
|
-
# created_at :datetime not null
|
14
|
-
# updated_at :datetime not null
|
15
|
-
#
|
16
|
-
# Indexes
|
17
|
-
#
|
18
|
-
# index_active_fields_on_customizable_type (customizable_type)
|
19
|
-
# index_active_fields_on_name_and_customizable_type (name,customizable_type) UNIQUE
|
20
|
-
#
|
21
|
-
module ActiveFields
|
22
|
-
class Field < ::ActiveRecord::Base
|
23
|
-
self.table_name = "active_fields"
|
24
|
-
|
25
|
-
include ActiveFields::FieldConcern
|
26
|
-
end
|
27
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# == Schema Information
|
4
|
-
#
|
5
|
-
# Table name: active_fields_values
|
6
|
-
#
|
7
|
-
# id :bigint not null, primary key
|
8
|
-
# customizable_type :string not null
|
9
|
-
# value :jsonb
|
10
|
-
# created_at :datetime not null
|
11
|
-
# updated_at :datetime not null
|
12
|
-
# customizable_id :bigint not null
|
13
|
-
# active_field_id :bigint not null
|
14
|
-
#
|
15
|
-
# Indexes
|
16
|
-
#
|
17
|
-
# index_active_fields_values_on_customizable_and_field (customizable_type,customizable_id,active_field_id) UNIQUE
|
18
|
-
# index_active_fields_values_on_active_field_id (active_field_id)
|
19
|
-
#
|
20
|
-
# Foreign Keys
|
21
|
-
#
|
22
|
-
# active_fields_values_active_field_id_fk (active_field_id => active_fields.id)
|
23
|
-
#
|
24
|
-
module ActiveFields
|
25
|
-
class Value < ::ActiveRecord::Base
|
26
|
-
self.table_name = "active_fields_values"
|
27
|
-
|
28
|
-
include ActiveFields::ValueConcern
|
29
|
-
end
|
30
|
-
end
|