syrup_form_object 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
#Syrup::FormObject
|
2
2
|
|
3
3
|
This is a simple implementation of the FormObject... pattern?
|
4
4
|
|
5
|
-
|
5
|
+
##Installation
|
6
6
|
|
7
7
|
gem install syrup_form_object
|
8
8
|
|
@@ -10,7 +10,7 @@ or in the *Gemfile*
|
|
10
10
|
|
11
11
|
gem 'syrup_form_object'
|
12
12
|
|
13
|
-
|
13
|
+
##Examples
|
14
14
|
|
15
15
|
class EventCreateForm < Syrup::FormObject
|
16
16
|
attr_accessor :event
|
@@ -31,7 +31,7 @@ or in the *Gemfile*
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
##Some sources for Form Objects
|
35
35
|
|
36
36
|
https://github.com/apotonick/reform An implementation of Form Objects
|
37
37
|
|
data/lib/syrup/form_object.rb
CHANGED
@@ -1,11 +1,31 @@
|
|
1
1
|
require 'virtus'
|
2
2
|
|
3
3
|
class Syrup::FormObject
|
4
|
-
include Virtus
|
4
|
+
include Virtus.model
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
include ActiveModel::Conversion
|
8
|
+
include ActiveModel::Validations
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def accepts_nested_attributes_for(*relations)
|
12
|
+
relations.each do |relation|
|
13
|
+
build_attributes_setter relation
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# build_attributes_setter 'address'
|
18
|
+
#
|
19
|
+
# def address_attributes=(attributes)
|
20
|
+
# address.attributes=attributes
|
21
|
+
# end
|
22
|
+
|
23
|
+
def build_attributes_setter(relation)
|
24
|
+
module_eval <<-EOH
|
25
|
+
def #{relation}_attributes=(attributes)
|
26
|
+
#{relation}.attributes=attributes
|
27
|
+
end
|
28
|
+
EOH
|
9
29
|
end
|
10
30
|
end
|
11
31
|
|
@@ -23,4 +43,8 @@ class Syrup::FormObject
|
|
23
43
|
|
24
44
|
def build; end
|
25
45
|
|
46
|
+
def persisted?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
26
50
|
end
|
data/lib/syrup/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syrup_form_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,9 +44,9 @@ files:
|
|
44
44
|
- lib/syrup.rb
|
45
45
|
- lib/syrup/form_object.rb
|
46
46
|
- lib/syrup/version.rb
|
47
|
-
- spec/lib/syrup/
|
47
|
+
- spec/lib/syrup/form_object_spec.rb
|
48
48
|
- spec/spec_helper.rb
|
49
|
-
-
|
49
|
+
- syrup_form_object.gemspec
|
50
50
|
homepage: https://github.com/alexsiri7/syrup_form_object
|
51
51
|
licenses:
|
52
52
|
- MIT
|