form_core 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/db/migrate/20170430191336_create_form_core_fields.rb +1 -1
- data/lib/form_core/concerns/models/form.rb +3 -6
- data/lib/form_core/version.rb +1 -1
- data/lib/form_core/virtual_model.rb +39 -2
- metadata +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fef835a9628708161f1763a6126d849e5f94c6a6
|
4
|
+
data.tar.gz: 56d5cd8b058df6b6661f0d49ffe9661b8c2252d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79e934f015fac242f398f89c56c6f727f3a8c2126c8ce51086a8bd4d284b90589f09a1906cedad1f54875258df292d5ee60af4964ceba1f8b385fa1eada29ca
|
7
|
+
data.tar.gz: 6a1365efd537b40a221ba05807fb69b20b0e562ad37600f1a35063bce297f306315eeefd77798b1ee5bfad8d0adda9fbeb1f1c23b53891f6dc3035f83b1d9bc5
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ class CreateFormCoreFields < ActiveRecord::Migration[5.1]
|
|
6
6
|
t.text :validations
|
7
7
|
t.text :static_default_value
|
8
8
|
t.text :options
|
9
|
-
t.string :type, null: false
|
9
|
+
t.string :type, null: false, index: true
|
10
10
|
t.references :form, foreign_key: {to_table: :form_core_forms}
|
11
11
|
|
12
12
|
t.timestamps
|
@@ -7,13 +7,10 @@ module FormCore::Concerns
|
|
7
7
|
has_many :fields
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def to_virtual_model(model_name: DEFAULT_MODEL_NAME,
|
13
|
-
fields_scope: DEFAULT_FIELDS_SCOPE,
|
10
|
+
def to_virtual_model(model_name: "Form",
|
11
|
+
fields_scope: proc { |fields| fields },
|
14
12
|
overrides: {})
|
15
|
-
model =
|
16
|
-
model.model_name = model_name
|
13
|
+
model = FormCore.virtual_model_class.build model_name
|
17
14
|
|
18
15
|
fields_scope.call(fields).each do |f|
|
19
16
|
f.interpret_to model, overrides: overrides.fetch(f.name, {})
|
data/lib/form_core/version.rb
CHANGED
@@ -2,10 +2,47 @@ require "duck_record"
|
|
2
2
|
|
3
3
|
module FormCore
|
4
4
|
class VirtualModel < ::DuckRecord::Base
|
5
|
+
|
6
|
+
# Returns the contents of the record as a nicely formatted string.
|
7
|
+
def inspect
|
8
|
+
# We check defined?(@attributes) not to issue warnings if the object is
|
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
|
19
|
+
|
20
|
+
"#<VirtualModel:#{self.class.name}:#{object_id} #{inspection}>"
|
21
|
+
end
|
22
|
+
|
5
23
|
public_class_method :define_method
|
6
24
|
class << self
|
7
|
-
def
|
8
|
-
@
|
25
|
+
def name
|
26
|
+
@name ||= "Form"
|
27
|
+
end
|
28
|
+
|
29
|
+
def name=(value)
|
30
|
+
value = value.classify
|
31
|
+
raise ArgumentError, "`value` isn't a valid class name" if value.blank?
|
32
|
+
|
33
|
+
@_name = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def build(name = nil)
|
37
|
+
klass = Class.new(self)
|
38
|
+
klass.name = name
|
39
|
+
klass
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a string like 'Post(id:integer, title:string, body:text)'
|
43
|
+
def inspect
|
44
|
+
attr_list = attribute_types.map { |name, type| "#{name}: #{type.type}" } * ", "
|
45
|
+
"#<VirtualModel:#{name}:#{object_id} #{attr_list}>"
|
9
46
|
end
|
10
47
|
end
|
11
48
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,32 +28,18 @@ dependencies:
|
|
28
28
|
name: duck_record
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: sqlite3
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
description: |
|
56
|
-
A Rails engine
|
42
|
+
A Rails engine providing ability to generate dynamic form.
|
57
43
|
It's would make such as dynamic fields of model or questionnaire easily.
|
58
44
|
email:
|
59
45
|
- jasl9187@hotmail.com
|
@@ -99,5 +85,5 @@ rubyforge_project:
|
|
99
85
|
rubygems_version: 2.6.11
|
100
86
|
signing_key:
|
101
87
|
specification_version: 4
|
102
|
-
summary: A Rails engine
|
88
|
+
summary: A Rails engine providing ability to generate dynamic form.
|
103
89
|
test_files: []
|