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
@@ -1,3 +1,5 @@
1
+ *.gem
1
2
  custom_plan.rb
2
3
  Gemfile.lock
3
- zeus.json
4
+ zeus.json
5
+ syrup_form_object-0.0.1.gem
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- ==Syrup::FormObject
1
+ #Syrup::FormObject
2
2
 
3
3
  This is a simple implementation of the FormObject... pattern?
4
4
 
5
- ==Installation
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
- ==Examples
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
- ==Some sources for Form Objects
34
+ ##Some sources for Form Objects
35
35
 
36
36
  https://github.com/apotonick/reform An implementation of Form Objects
37
37
 
@@ -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
- def self.accepts_nested_attributes_for(*relations)
7
- relations.each do |relation|
8
- module_eval "def #{relation}_attributes=(attributes); #{relation}.attributes=attributes; end"
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
@@ -1,3 +1,3 @@
1
1
  module Syrup
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class TestItem
4
- include Virtus
4
+ include Virtus.model
5
5
  attribute :test_item_value, Integer
6
6
  end
7
7
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  require 'rspec'
2
+
3
+ module ActiveModel
4
+ module Naming; end
5
+ module Conversion; end
6
+ module Validations; end
7
+ end
8
+
2
9
  require 'syrup'
3
10
 
4
11
  RSpec.configure do |config|
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.2
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/form_object.rb
47
+ - spec/lib/syrup/form_object_spec.rb
48
48
  - spec/spec_helper.rb
49
- - syrum_form_object.gemspec
49
+ - syrup_form_object.gemspec
50
50
  homepage: https://github.com/alexsiri7/syrup_form_object
51
51
  licenses:
52
52
  - MIT