form_core 0.1.1 → 0.1.5

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: 2c0f530095dc86581b8ac76253262597a1ea78fc02c993ccd18f32f33967a5c6
4
- data.tar.gz: 6015de67d6a702394c97846d04c14d44f71b083884c793e41b159d43499173f5
3
+ metadata.gz: eaf54d23bf11c6b6fd8e5c3438a7b829622d56cf3db3dd42c89a275b9d65262b
4
+ data.tar.gz: 8a21227cd6d63140bc8933d2733dc8d5e9a0a89c0e6830f22963b9ebdbf349ef
5
5
  SHA512:
6
- metadata.gz: 67d3f56412abaac9c599e295f872a92aa745d79d2eca7b579bde47918ca650ebabd5c38610f946a0b1a61ca2eec94a137e37abc08c0daf3b67cf149b31760ae7
7
- data.tar.gz: 529af9997500def71236120ce8c98a0e172d3d119ed53d80d450695cacd2365fa788ffe5503c801b0a2682c2813dd0f3e29a1f9e463a74a2ff51c97041eed338
6
+ metadata.gz: 1860f64f8c0e27c2a35411cfbe7cfb788b5290b23a3a3c7edfc3a3d9776403a55d753d2b86b055a715819b43b434fe5f8c5533245179d8760249f842c48a17f6
7
+ data.tar.gz: 75162ebf49fc713140a07a32a3381363e9f511ec8d4a2b8ee4c56d6e46334f66751ed83a9bc8db4c14ca96a1a2bae3d23387475cbbdbac8a48846876d212b716
@@ -6,6 +6,6 @@ module FormCore
6
6
 
7
7
  self.table_name = "forms"
8
8
 
9
- has_many :fields
9
+ has_many :fields, dependent: :destroy
10
10
  end
11
11
  end
@@ -3,7 +3,6 @@
3
3
  class CreateForms < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :forms do |t|
6
- t.string :name, null: false, index: {unique: true}
7
6
  t.string :type, null: false, index: true
8
7
 
9
8
  t.timestamps
@@ -24,20 +24,20 @@ module FormCore
24
24
 
25
25
  private
26
26
 
27
- def new_or_raise_decoding_error
28
- if strict?
29
- raise DecodingDataCorrupted
30
- else
31
- object_class.new
27
+ def new_or_raise_decoding_error
28
+ if strict?
29
+ raise DecodingDataCorrupted
30
+ else
31
+ object_class.new
32
+ end
32
33
  end
33
- end
34
34
 
35
- def valid_attribute_names
36
- object_class.attribute_names + object_class._embeds_reflections.keys
37
- end
35
+ def valid_attribute_names
36
+ object_class.attribute_names + object_class._embeds_reflections.keys
37
+ end
38
38
 
39
- def valid_attributes(hash)
40
- hash.slice(*valid_attribute_names)
41
- end
39
+ def valid_attributes(hash)
40
+ hash.slice(*valid_attribute_names)
41
+ end
42
42
  end
43
43
  end
@@ -9,9 +9,7 @@ module FormCore
9
9
  end
10
10
 
11
11
  def load(hash)
12
- if hash.nil? || !hash.respond_to?(:to_h)
13
- return new_or_raise_decoding_error
14
- end
12
+ return new_or_raise_decoding_error if hash.nil? || !hash.respond_to?(:to_h)
15
13
 
16
14
  object_class.new valid_attributes(hash)
17
15
  end
@@ -23,19 +23,15 @@ module FormCore
23
23
  def load(yaml)
24
24
  return object_class.new if yaml.blank?
25
25
 
26
- unless yaml.is_a?(String) && /^---/.match?(yaml)
27
- return new_or_raise_decoding_error
28
- end
26
+ return new_or_raise_decoding_error unless yaml.is_a?(String) && /^---/.match?(yaml)
29
27
 
30
28
  decoded =
31
29
  if safe_mode?
32
30
  YAML.safe_load(yaml, YAMLCoder.whitelist_classes)
33
31
  else
34
- YAML.load(yaml)
32
+ YAML.safe_load(yaml)
35
33
  end
36
- unless decoded.is_a? Hash
37
- return new_or_raise_decoding_error
38
- end
34
+ return new_or_raise_decoding_error unless decoded.is_a? Hash
39
35
 
40
36
  object_class.new valid_attributes(decoded)
41
37
  end
@@ -8,7 +8,7 @@ module FormCore::Concerns
8
8
  NAME_REGEX = /\A[a-z][a-z_0-9]*\z/.freeze
9
9
 
10
10
  included do
11
- enum accessibility: {read_and_write: 0, readonly: 1, hidden: 2},
11
+ enum accessibility: { read_and_write: 0, readonly: 1, hidden: 2 },
12
12
  _prefix: :access
13
13
 
14
14
  serialize :validations
@@ -16,11 +16,11 @@ module FormCore::Concerns
16
16
 
17
17
  validates :name,
18
18
  presence: true,
19
- uniqueness: {scope: :form},
20
- exclusion: {in: FormCore.reserved_names},
21
- format: {with: NAME_REGEX}
19
+ uniqueness: { scope: :form },
20
+ exclusion: { in: FormCore.reserved_names },
21
+ format: { with: NAME_REGEX }
22
22
  validates :accessibility,
23
- inclusion: {in: accessibilities.keys.map(&:to_sym)}
23
+ inclusion: { in: accessibilities.keys.map(&:to_sym) }
24
24
 
25
25
  after_initialize do
26
26
  self.validations ||= {}
@@ -54,9 +54,7 @@ module FormCore::Concerns
54
54
  default_value = overrides.fetch(:default_value, self.default_value)
55
55
  model.attribute name, stored_type, default: default_value
56
56
 
57
- if accessibility == :readonly
58
- model.attr_readonly name
59
- end
57
+ model.attr_readonly name if accessibility == :readonly
60
58
 
61
59
  interpret_validations_to model, accessibility, overrides
62
60
  interpret_extra_to model, accessibility, overrides
@@ -66,22 +64,20 @@ module FormCore::Concerns
66
64
 
67
65
  protected
68
66
 
69
- def interpret_validations_to(model, accessibility, overrides = {})
70
- validations = overrides.fetch(:validations, (self.validations || {}))
71
- validation_options = overrides.fetch(:validation_options) { self.options.fetch(:validation, {}) }
67
+ def interpret_validations_to(model, accessibility, overrides = {})
68
+ validations = overrides.fetch(:validations, (self.validations || {}))
69
+ validation_options = overrides.fetch(:validation_options) { self.options.fetch(:validation, {}) }
72
70
 
73
- if accessibility == :read_and_write && validations.present?
74
- model.validates name, **validations, **validation_options
71
+ model.validates name, **validations, **validation_options if accessibility == :read_and_write && validations.present?
75
72
  end
76
- end
77
73
 
78
- def interpret_extra_to(_model, _accessibility, _overrides = {}); end
74
+ def interpret_extra_to(_model, _accessibility, _overrides = {}); end
79
75
 
80
- def check_model_validity!(model)
81
- unless model.is_a?(Class) && model < ::FormCore::VirtualModel
82
- raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
76
+ def check_model_validity!(model)
77
+ unless model.is_a?(Class) && model < ::FormCore::VirtualModel
78
+ raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
79
+ end
83
80
  end
84
- end
85
81
  end
86
82
  end
87
83
  end
@@ -5,16 +5,6 @@ module FormCore::Concerns
5
5
  module Form
6
6
  extend ActiveSupport::Concern
7
7
 
8
- NAME_REGEX = /\A[a-z][a-z_0-9]*\z/.freeze
9
-
10
- included do
11
- validates :name,
12
- presence: true,
13
- uniqueness: true,
14
- exclusion: {in: FormCore.reserved_names},
15
- format: {with: NAME_REGEX}
16
- end
17
-
18
8
  def to_virtual_model(model_name: "Form",
19
9
  fields_scope: proc { |fields| fields },
20
10
  overrides: {})
@@ -38,11 +28,11 @@ module FormCore::Concerns
38
28
 
39
29
  private
40
30
 
41
- def check_model_validity!(model)
42
- unless model.is_a?(Class) && model < ::FormCore::VirtualModel
43
- raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
31
+ def check_model_validity!(model)
32
+ unless model.is_a?(Class) && model < ::FormCore::VirtualModel
33
+ raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
34
+ end
44
35
  end
45
- end
46
36
  end
47
37
  end
48
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormCore
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -11,9 +11,7 @@ module FormCore
11
11
  inspection =
12
12
  if defined?(@attributes) && @attributes
13
13
  self.class.attribute_names.collect do |name|
14
- if has_attribute?(name)
15
- "#{name}: #{attribute_for_inspect(name)}"
16
- end
14
+ "#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name)
17
15
  end.compact.join(", ")
18
16
  else
19
17
  "not initialized"
@@ -24,7 +22,7 @@ module FormCore
24
22
 
25
23
  def serializable_hash(options = {})
26
24
  options = (options || {}).reverse_merge include: self.class._embeds_reflections.keys
27
- super options
25
+ super(**options)
28
26
  end
29
27
 
30
28
  # Hack
@@ -51,9 +49,7 @@ module FormCore
51
49
  end
52
50
 
53
51
  def coder=(klass)
54
- unless klass && klass < Coder
55
- raise ArgumentError, "#{klass} should be sub-class of #{Coder}."
56
- end
52
+ raise ArgumentError, "#{klass} should be sub-class of #{Coder}." unless klass && klass < Coder
57
53
 
58
54
  @_coder = klass.new(self)
59
55
  end
data/lib/form_core.rb CHANGED
@@ -18,9 +18,7 @@ module FormCore
18
18
  end
19
19
 
20
20
  def virtual_model_class=(klass)
21
- unless klass && klass < VirtualModel
22
- raise ArgumentError, "#{klass} should be sub-class of #{VirtualModel}."
23
- end
21
+ raise ArgumentError, "#{klass} should be sub-class of #{VirtualModel}." unless klass && klass < VirtualModel
24
22
 
25
23
  @reserved_names = nil
26
24
  @virtual_model_class = klass
@@ -38,9 +36,7 @@ module FormCore
38
36
  end
39
37
 
40
38
  def virtual_model_coder_class=(klass)
41
- unless klass && klass < Coder
42
- raise ArgumentError, "#{klass} should be sub-class of #{Coder}."
43
- end
39
+ raise ArgumentError, "#{klass} should be sub-class of #{Coder}." unless klass && klass < Coder
44
40
 
45
41
  @virtual_model_coder_class = klass
46
42
  end
metadata CHANGED
@@ -1,49 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-21 00:00:00.000000000 Z
11
+ date: 2021-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activeentity
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.0.1.beta5
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.0.1.beta5
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rails
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 6.0.0.beta3
19
+ version: '6.1'
34
20
  - - "<"
35
21
  - !ruby/object:Gem::Version
36
- version: '7'
22
+ version: '8'
37
23
  type: :runtime
38
24
  prerelease: false
39
25
  version_requirements: !ruby/object:Gem::Requirement
40
26
  requirements:
41
27
  - - ">="
42
28
  - !ruby/object:Gem::Version
43
- version: 6.0.0.beta3
29
+ version: '6.1'
44
30
  - - "<"
45
31
  - !ruby/object:Gem::Version
46
- version: '7'
32
+ version: '8'
47
33
  description: |
48
34
  A Rails engine providing ability to generate dynamic form.
49
35
  It's would make such as dynamic fields of model or questionnaire easily.
@@ -76,7 +62,7 @@ homepage: https://github.com/rails-engine/form_core
76
62
  licenses:
77
63
  - MIT
78
64
  metadata: {}
79
- post_install_message:
65
+ post_install_message:
80
66
  rdoc_options: []
81
67
  require_paths:
82
68
  - lib
@@ -91,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
77
  - !ruby/object:Gem::Version
92
78
  version: '0'
93
79
  requirements: []
94
- rubygems_version: 3.0.3
95
- signing_key:
80
+ rubygems_version: 3.2.32
81
+ signing_key:
96
82
  specification_version: 4
97
83
  summary: A Rails engine providing ability to generate dynamic form.
98
84
  test_files: []