form_core 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c0f530095dc86581b8ac76253262597a1ea78fc02c993ccd18f32f33967a5c6
4
- data.tar.gz: 6015de67d6a702394c97846d04c14d44f71b083884c793e41b159d43499173f5
3
+ metadata.gz: a016a1344a482ebe99e58d9daea62366b5f9ffe57e78bd2b64b1d10274f2292c
4
+ data.tar.gz: 145bb989f255f07635a799351d715f5cbc5f801bdb203913afe7495baf44815a
5
5
  SHA512:
6
- metadata.gz: 67d3f56412abaac9c599e295f872a92aa745d79d2eca7b579bde47918ca650ebabd5c38610f946a0b1a61ca2eec94a137e37abc08c0daf3b67cf149b31760ae7
7
- data.tar.gz: 529af9997500def71236120ce8c98a0e172d3d119ed53d80d450695cacd2365fa788ffe5503c801b0a2682c2813dd0f3e29a1f9e463a74a2ff51c97041eed338
6
+ metadata.gz: 39a93c46530072522e9cfc9212e81c5d90b0e2f62887d8ccfde56f4bcca8f059f0d0dda2a2ed87564939727a0c177e2e78feddd382d15b97d655695076428b92
7
+ data.tar.gz: d765f57550efb4587eccf55aeb4cabf7532c7e5744f848e71ac2a79decac93b2a339ebf314d230550c6f32bc6218dcf5a9e94aca87ee2e0e397090afb94162b4
@@ -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,7 @@
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}
6
+ t.string :name, null: false, index: { unique: true }
7
7
  t.string :type, null: false, index: true
8
8
 
9
9
  t.timestamps
@@ -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
@@ -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,18 @@ 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
+ raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass" unless model.is_a?(Class) && model < ::FormCore::VirtualModel
83
78
  end
84
- end
85
79
  end
86
80
  end
87
81
  end
@@ -11,8 +11,8 @@ module FormCore::Concerns
11
11
  validates :name,
12
12
  presence: true,
13
13
  uniqueness: true,
14
- exclusion: {in: FormCore.reserved_names},
15
- format: {with: NAME_REGEX}
14
+ exclusion: { in: FormCore.reserved_names },
15
+ format: { with: NAME_REGEX }
16
16
  end
17
17
 
18
18
  def to_virtual_model(model_name: "Form",
@@ -38,11 +38,11 @@ module FormCore::Concerns
38
38
 
39
39
  private
40
40
 
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"
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"
44
+ end
44
45
  end
45
- end
46
46
  end
47
47
  end
48
48
  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.2"
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"
@@ -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
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-21 00:00:00.000000000 Z
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeentity
@@ -16,21 +16,21 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.1.beta5
19
+ version: 0.0.1.beta7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.1.beta5
26
+ version: 0.0.1.beta7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.0.beta3
33
+ version: 6.0.0.rc1
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '7'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 6.0.0.beta3
43
+ version: 6.0.0.rc1
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '7'