formwandler 0.3.0 → 0.3.1

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: 8c540ca340cf674027438511baf2a5626a3c7381
4
- data.tar.gz: c6f4a99dfc96dc116f7186411756709ba620bf0a
3
+ metadata.gz: f9d6cfc5b1013e3204f17c536b1d487df7afe83e
4
+ data.tar.gz: e11b639f71da8ea99e114dfbc89dbaf1c334ba6d
5
5
  SHA512:
6
- metadata.gz: 787033015fb055d67ed2c6b8317bb195dd93d466cbf1d2f5f1283cda58ce229315b06372df4a1eded39117e59f6fea6868df446f62a545458f883528f4c09085
7
- data.tar.gz: 8abd297a626321a6e12db1fa7efcc4e3a85d3757339cdfb598fc93d664b59102fe7e47064f44922f5d5d1824cece975720687b8a942c7f5495ff7b4407130423
6
+ metadata.gz: 3c1350ec9865df57a2f049d16d3bdc86817128ad8078636046198e038c59912d54b250899a7be1f3c07b33f7dc7a835dd448ef9ea41779a68566c227d350fa9a
7
+ data.tar.gz: adbfc536119e99a772827ed26718f342d4cd0deb836453db5e69d553f141cae62218d6402e8741d222bfab21514dc4cd8fa51b1ebe1033626a40cf73382a4125
data/lib/formwandler.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require_relative 'formwandler/version'
1
2
  require_relative 'formwandler/form'
2
3
 
3
4
  require_relative 'formwandler/railtie'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Formwandler
4
+ module FormLoader
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def load_form(opts = {})
9
+ before_action :_formwandler_load_form, opts
10
+ end
11
+
12
+ def skip_load_form(opts = {})
13
+ skip_before_action :_formwandler_load_form, opts
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def _formwandler_load_form
20
+ form_instance = form_class.new(models: {inferred_resource_name.to_sym => instance_variable_get("@#{inferred_resource_name}")}, controller: self)
21
+ instance_variable_set("@#{form_instance_name}", form_instance)
22
+ end
23
+
24
+ def form_class_name
25
+ "#{inferred_resource_name}_form".camelize
26
+ end
27
+
28
+ def form_class
29
+ form_class_name.constantize
30
+ end
31
+
32
+ def form_instance_name
33
+ form_class_name.underscore
34
+ end
35
+
36
+ def inferred_resource_name
37
+ controller_name.singularize
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'form_loader'
4
+
5
+ module Formwandler
6
+ class Railtie < Rails::Railtie
7
+ initializer 'formwandler.form_loader' do
8
+ ActionController::Base.send(:include, Formwandler::FormLoader)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Formwandler
2
+ VERSION = '0.3.1'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formwandler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Bilharz
@@ -119,6 +119,9 @@ files:
119
119
  - lib/formwandler/field.rb
120
120
  - lib/formwandler/field_definition.rb
121
121
  - lib/formwandler/form.rb
122
+ - lib/formwandler/form_loader.rb
123
+ - lib/formwandler/railtie.rb
124
+ - lib/formwandler/version.rb
122
125
  homepage: https://github.com/sbilharz/formwandler
123
126
  licenses:
124
127
  - MIT