form_core 0.0.14 → 0.1.4

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
- SHA1:
3
- metadata.gz: c0ff92c104fbdbeb9f7fbd170b34868a2697ea1e
4
- data.tar.gz: 28003e17cc44fd89b86cb9c2019527332902f081
2
+ SHA256:
3
+ metadata.gz: '07928a7711775a7ce8cdfaf530713730dfc5a72dd771bc6a9cf6b3ff32bf8812'
4
+ data.tar.gz: fa3857b1953ab4ba80868b3347ddc619c3edbd60d93eba1441ff0f1318eb5b15
5
5
  SHA512:
6
- metadata.gz: 9c9c08f314a65c66bb211e61855e0f933292897a46231cb07f21e2c637fcb6486efd6f0844759d4a6a8188ecbd874fbab161fb014a632889d2d876b2d9cb058a
7
- data.tar.gz: b1b79bd8edb0470183f4ec3c616a19d7912ef8e34fdb935e65647d1491348e6f23d86ce0ec8338850d0ab916c4dcb7bf2a40e7e0379765abbb6cb8b283c2dbfb
6
+ metadata.gz: e6f6cb884b37fa4a923d065840ae07f2d1dedad44867418d24115e9c7109ba58c1a36cfa199d506279cd11162f937d58331c18dba8467fe27073a765e2fb7f09
7
+ data.tar.gz: c9ac5f4b33404314e2c6fab8b3ddcac8bdf2151e541e354de0f727e92c7b6b4fe99c109cb5581d7099762209075f6d6ed241d74ec096f82fadadfda3836e3818
data/README.md CHANGED
@@ -5,6 +5,13 @@ A Rails engine providing ability to generate dynamic form.
5
5
 
6
6
  ## Requirements
7
7
 
8
+ ### 0.1 branch
9
+
10
+ - MRI 2.5+
11
+ - Rails 6.0+
12
+
13
+ ### 0.0.1 branch
14
+
8
15
  - MRI 2.3+
9
16
  - Rails 5.0+
10
17
 
@@ -23,7 +30,7 @@ gem 'form_core'
23
30
  Or you may want to include the gem directly from GitHub:
24
31
 
25
32
  ```ruby
26
- gem 'form_core', github: 'jasl-lab/form_core'
33
+ gem 'form_core', github: 'rails-engine/form_core'
27
34
  ```
28
35
 
29
36
  And then execute:
@@ -49,7 +56,7 @@ $ bin/rails db:migrate
49
56
  Clone the repository.
50
57
 
51
58
  ```sh
52
- $ git clone https://github.com/jasl-lab/form_core.git
59
+ $ git clone https://github.com/rails-engine/form_core.git
53
60
  ```
54
61
 
55
62
  Change directory
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
16
16
  rdoc.rdoc_files.include("lib/**/*.rb")
17
17
  end
18
18
 
19
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
19
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
20
20
  load "rails/tasks/engine.rake"
21
21
 
22
22
  load "rails/tasks/statistics.rake"
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateForms < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  create_table :forms do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateFields < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  create_table :fields do |t|
@@ -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
@@ -28,7 +26,7 @@ module FormCore
28
26
 
29
27
  def reserved_names
30
28
  @reserved_names ||= Set.new(
31
- %i(def class module private public protected allocate new parent superclass) +
29
+ %i[def class module private public protected allocate new parent superclass] +
32
30
  virtual_model_class.instance_methods(true)
33
31
  )
34
32
  end
@@ -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
@@ -5,10 +5,10 @@ module FormCore::Concerns
5
5
  module Field
6
6
  extend ActiveSupport::Concern
7
7
 
8
- NAME_REGEX = /\A[a-z_][a-z_0-9]*\z/
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: self.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,23 +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 = {})
79
- end
74
+ def interpret_extra_to(_model, _accessibility, _overrides = {}); end
80
75
 
81
- def check_model_validity!(model)
82
- unless model.is_a?(Class) && model < ::FormCore::VirtualModel
83
- 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
84
80
  end
85
- end
86
81
  end
87
82
  end
88
83
  end
@@ -28,11 +28,11 @@ module FormCore::Concerns
28
28
 
29
29
  private
30
30
 
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"
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
34
35
  end
35
- end
36
36
  end
37
37
  end
38
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormCore
4
- VERSION = "0.0.14"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "duck_record"
3
+ require "active_entity"
4
4
 
5
5
  module FormCore
6
- class VirtualModel < ::DuckRecord::Base
6
+ class VirtualModel < ::ActiveEntity::Base
7
7
  # Returns the contents of the record as a nicely formatted string.
8
8
  def inspect
9
9
  # We check defined?(@attributes) not to issue warnings if the object is
@@ -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,11 +22,14 @@ 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
 
28
+ # Hack
29
+ ARRAY_WITHOUT_BLANK_PATTERN = "!ruby/array:ArrayWithoutBlank"
30
+
30
31
  def dump
31
- self.class.dump(self)
32
+ self.class.dump(self).gsub(ARRAY_WITHOUT_BLANK_PATTERN, "")
32
33
  end
33
34
 
34
35
  class << self
@@ -48,9 +49,7 @@ module FormCore
48
49
  end
49
50
 
50
51
  def coder=(klass)
51
- unless klass && klass < Coder
52
- raise ArgumentError, "#{klass} should be sub-class of #{Coder}."
53
- end
52
+ raise ArgumentError, "#{klass} should be sub-class of #{Coder}." unless klass && klass < Coder
54
53
 
55
54
  @_coder = klass.new(self)
56
55
  end
@@ -70,7 +69,7 @@ module FormCore
70
69
  end
71
70
 
72
71
  def _embeds_reflections
73
- _reflections.select { |_, v| v.is_a? DuckRecord::Reflection::EmbedsAssociationReflection }
72
+ _reflections.select { |_, v| v.is_a? ::ActiveEntity::Reflection::EmbeddedAssociationReflection }
74
73
  end
75
74
  end
76
75
  end
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-08 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activeentity
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: 6.1.0
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: '5.0'
26
+ version: 6.1.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: duck_record
28
+ name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 6.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '7'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 6.0.0
44
+ - - "<"
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: '7'
41
47
  description: |
42
48
  A Rails engine providing ability to generate dynamic form.
43
49
  It's would make such as dynamic fields of model or questionnaire easily.
@@ -66,11 +72,11 @@ files:
66
72
  - lib/form_core/version.rb
67
73
  - lib/form_core/virtual_model.rb
68
74
  - lib/tasks/form_core_tasks.rake
69
- homepage: https://github.com/jasl-lab/form_core
75
+ homepage: https://github.com/rails-engine/form_core
70
76
  licenses:
71
77
  - MIT
72
78
  metadata: {}
73
- post_install_message:
79
+ post_install_message:
74
80
  rdoc_options: []
75
81
  require_paths:
76
82
  - lib
@@ -85,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
91
  - !ruby/object:Gem::Version
86
92
  version: '0'
87
93
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.6.13
90
- signing_key:
94
+ rubygems_version: 3.1.4
95
+ signing_key:
91
96
  specification_version: 4
92
97
  summary: A Rails engine providing ability to generate dynamic form.
93
98
  test_files: []