association-soft-build 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sergey Tokarenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ AssociationSoftBuild
2
+ ====================
3
+
4
+ AssociationSoftBuild extends ActiveRecord to provide the possibility to build an association without affecting to the parent object.
5
+
6
+ # The problem
7
+
8
+ Lets imagine that we need to render something like this:
9
+
10
+ ```haml
11
+ .label New Comment
12
+ = simple_form_for post.comments.build do |f|
13
+ = f.input :post_id, as: :hidden
14
+ = f.input :body
15
+ = f.submit
16
+
17
+ .label Existing comments
18
+ %ul
19
+ - post.comments.each do |comment|
20
+ %li= simple_format(comment.body)
21
+ ```
22
+
23
+ Unfortunately, the native relation's `build` method will add the new
24
+ object to parent object's association set. In or case, the blank
25
+ comment will appear in "Existing comments" list.
26
+
27
+ # Solution
28
+
29
+ AssociationSoftBuild adds the `soft_build` method to relations, which doing all the same as native `build`, but not affects to parent object.
@@ -0,0 +1,7 @@
1
+ require 'association-soft-build/version'
2
+
3
+ module AssociationSoftBuild
4
+ autoload :Relation, 'association-soft-build/relation'
5
+ end
6
+
7
+ require 'association-soft-build/railtie'
@@ -0,0 +1,12 @@
1
+ require 'active_record/railtie'
2
+
3
+ module AssocitionaSoftBuild
4
+ class Railtie < Rails::Railtie
5
+ #TODO uncoment this and make it work in tests
6
+ #initializer 'association-soft-build.configure_rails_initialization' do
7
+ ActiveSupport.on_load :active_record do
8
+ ActiveRecord::Relation.send :include, AssociationSoftBuild::Relation
9
+ end
10
+ #end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module AssociationSoftBuild
2
+ module Relation
3
+ extend ActiveSupport::Concern
4
+
5
+ def soft_build
6
+ klass.new(where_values_hash)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module AssociationSoftBuild
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: association-soft-build
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergey Tokarenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '4.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '4.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '4.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '4.1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.1'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ActiveRecord plugin which provides the possibility to build an association
79
+ without affecting to parent object.
80
+ email: private.tokarenko.sergey@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - lib/association-soft-build/railtie.rb
86
+ - lib/association-soft-build/relation.rb
87
+ - lib/association-soft-build/version.rb
88
+ - lib/association-soft-build.rb
89
+ - LICENSE
90
+ - README.md
91
+ homepage: https://github.com/stokarenko/association-soft-build
92
+ licenses:
93
+ - MIT
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.23.2
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: ActiveRecord plugin which provides the possibility to build an association
116
+ without affecting to parent object.
117
+ test_files: []