form_core 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: fef835a9628708161f1763a6126d849e5f94c6a6
4
- data.tar.gz: 56d5cd8b058df6b6661f0d49ffe9661b8c2252d3
3
+ metadata.gz: 88c1f8ae832ce81300e9a18e3da6e421b6acb4cd
4
+ data.tar.gz: a8f383d55d6ffb29b9622997d2a8ddf36de85cf4
5
5
  SHA512:
6
- metadata.gz: f79e934f015fac242f398f89c56c6f727f3a8c2126c8ce51086a8bd4d284b90589f09a1906cedad1f54875258df292d5ee60af4964ceba1f8b385fa1eada29ca
7
- data.tar.gz: 6a1365efd537b40a221ba05807fb69b20b0e562ad37600f1a35063bce297f306315eeefd77798b1ee5bfad8d0adda9fbeb1f1c23b53891f6dc3035f83b1d9bc5
6
+ metadata.gz: 95b46ed6033fd52676d9c0d9eecf4f72cc69b3627520e9993f112dfc4ae295f02c2da6b961f002d2373bb1d9d2eb0da82b6ec2b2354d10d7a95688bedc4312ab
7
+ data.tar.gz: 1044c2dff56c1e3df3909497ca794e509969a0364578744f3d5c9c7d14b705f2a771d2921967796446d403980d41605f6045a2e1ee54c8224fabcf775a9ed15b
data/README.md CHANGED
@@ -5,7 +5,7 @@ A Rails engine providing ability to generate dynamic form.
5
5
 
6
6
  ## Usage
7
7
 
8
- TODO
8
+ See demo for now.
9
9
 
10
10
  ## Installation
11
11
 
@@ -1,4 +1,4 @@
1
- class CreateFormCoreForms < ActiveRecord::Migration[5.1]
1
+ class CreateForms < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :form_core_forms do |t|
4
4
  t.string :type, null: false, index: true
@@ -1,4 +1,4 @@
1
- class CreateFormCoreFields < ActiveRecord::Migration[5.1]
1
+ class CreateFields < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :form_core_fields do |t|
4
4
  t.string :name, null: false
@@ -12,12 +12,28 @@ module FormCore::Concerns
12
12
  overrides: {})
13
13
  model = FormCore.virtual_model_class.build model_name
14
14
 
15
+ append_to_virtual_model(model, fields_scope: fields_scope, overrides: overrides)
16
+ end
17
+
18
+ def append_to_virtual_model(model,
19
+ fields_scope: proc { |fields| fields },
20
+ overrides: {})
21
+ check_model_validity! model
22
+
15
23
  fields_scope.call(fields).each do |f|
16
24
  f.interpret_to model, overrides: overrides.fetch(f.name, {})
17
25
  end
18
26
 
19
27
  model
20
28
  end
29
+
30
+ private
31
+
32
+ def check_model_validity!(model)
33
+ unless model.is_a?(Class) && model < ::FormCore::VirtualModel
34
+ raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
35
+ end
36
+ end
21
37
  end
22
38
  end
23
39
  end
@@ -1,3 +1,3 @@
1
1
  module FormCore
2
- VERSION = '0.0.2'
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,15 +7,16 @@ module FormCore
7
7
  def inspect
8
8
  # We check defined?(@attributes) not to issue warnings if the object is
9
9
  # allocated but not initialized.
10
- inspection = if defined?(@attributes) && @attributes
11
- self.class.attribute_names.collect do |name|
12
- if has_attribute?(name)
13
- "#{name}: #{attribute_for_inspect(name)}"
14
- end
15
- end.compact.join(", ")
16
- else
17
- "not initialized"
18
- end
10
+ inspection =
11
+ if defined?(@attributes) && @attributes
12
+ self.class.attribute_names.collect do |name|
13
+ if has_attribute?(name)
14
+ "#{name}: #{attribute_for_inspect(name)}"
15
+ end
16
+ end.compact.join(", ")
17
+ else
18
+ "not initialized"
19
+ end
19
20
 
20
21
  "#<VirtualModel:#{self.class.name}:#{object_id} #{inspection}>"
21
22
  end
@@ -23,7 +24,7 @@ module FormCore
23
24
  public_class_method :define_method
24
25
  class << self
25
26
  def name
26
- @name ||= "Form"
27
+ @_name ||= "Form"
27
28
  end
28
29
 
29
30
  def name=(value)
@@ -39,7 +40,7 @@ module FormCore
39
40
  klass
40
41
  end
41
42
 
42
- # Returns a string like 'Post(id:integer, title:string, body:text)'
43
+ # Returns a string like "Post(id:integer, title:string, body:text)"
43
44
  def inspect
44
45
  attr_list = attribute_types.map { |name, type| "#{name}: #{type.type}" } * ", "
45
46
  "#<VirtualModel:#{name}:#{object_id} #{attr_list}>"
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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-12 00:00:00.000000000 Z
11
+ date: 2017-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -53,8 +53,8 @@ files:
53
53
  - app/models/form_core/application_record.rb
54
54
  - app/models/form_core/field.rb
55
55
  - app/models/form_core/form.rb
56
- - db/migrate/20170430190404_create_form_core_forms.rb
57
- - db/migrate/20170430191336_create_form_core_fields.rb
56
+ - db/migrate/20170430190404_create_forms.rb
57
+ - db/migrate/20170430191336_create_fields.rb
58
58
  - lib/form_core.rb
59
59
  - lib/form_core/concerns/models/field.rb
60
60
  - lib/form_core/concerns/models/form.rb
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.6.11
85
+ rubygems_version: 2.6.12
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: A Rails engine providing ability to generate dynamic form.