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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5445ceba04d699e653eb979f4bbb4d47b2a02d35
4
- data.tar.gz: 43378b5c8cc8ece05bf173e942a124edda795595
3
+ metadata.gz: fef835a9628708161f1763a6126d849e5f94c6a6
4
+ data.tar.gz: 56d5cd8b058df6b6661f0d49ffe9661b8c2252d3
5
5
  SHA512:
6
- metadata.gz: 054dd0d3d050c6700bea922a5fe6d672fae0b18e429869808da7576ea98b894e8be4f8dade8b625970ab68e319e9078e423068a76c120722e79427939f1158c7
7
- data.tar.gz: de14cd9112daf2557a8548face1551591b8eaa8e4ab157b24306f35d1aaa59d16c6475761cadf9a0e4551320c5a14cf942ce981984395c3cf33d363abe8289d5
6
+ metadata.gz: f79e934f015fac242f398f89c56c6f727f3a8c2126c8ce51086a8bd4d284b90589f09a1906cedad1f54875258df292d5ee60af4964ceba1f8b385fa1eada29ca
7
+ data.tar.gz: 6a1365efd537b40a221ba05807fb69b20b0e562ad37600f1a35063bce297f306315eeefd77798b1ee5bfad8d0adda9fbeb1f1c23b53891f6dc3035f83b1d9bc5
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Form Core
2
2
  ====
3
3
 
4
- A Rails engine provides ability to generate dynamic form.
4
+ A Rails engine providing ability to generate dynamic form.
5
5
 
6
6
  ## Usage
7
7
 
@@ -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
- DEFAULT_MODEL_NAME = "Form"
11
- DEFAULT_FIELDS_SCOPE = proc { |fields| fields }
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 = Class.new(FormCore.virtual_model_class)
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, {})
@@ -1,3 +1,3 @@
1
1
  module FormCore
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -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 model_name=(name)
8
- @_model_name = ActiveModel::Name.new(self, nil, name.classify)
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.1
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-05-30 00:00:00.000000000 Z
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 provides ability to generate dynamic form.
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 provides ability to generate dynamic form.
88
+ summary: A Rails engine providing ability to generate dynamic form.
103
89
  test_files: []