association_reflections 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e614b87d1c3b1b42c92de822f7c6a5c9053179209a436bf06d1257f115794a94
4
+ data.tar.gz: 975aca1876e49c9644fbff4d28788febfc3aec0da2d5220bab778e4e969639c1
5
+ SHA512:
6
+ metadata.gz: aa92fe6b2fec1cf14343736a64ea9ef62ee991575527ece534f4e5bef8723ef53a40cad25adb60378d0475d2246b9b843abdf2425947d366a067dc012ff1db26
7
+ data.tar.gz: 9ddd4ce3a6029f0ba2435fdb8cee3b2bc04627976178ba4f079720def63a5995b5e0e2281df4c1506aaa1bd8c8f9f4c56780bca3967ef4f512ac662b28f37e8a
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AssociationReflections
4
+ require_relative 'association_reflections/association'
5
+ require_relative 'association_reflections/concern'
6
+ require_relative 'association_reflections/version'
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AssociationReflections
4
+ class Association
5
+
6
+ attr_accessor :params
7
+
8
+ def initialize(params)
9
+ @params = ::JSON.parse(params.to_json, symbolize_names: false)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AssociationReflections
4
+ module Concern
5
+ require 'active_support/concern'
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+
11
+ attr_accessor :association_reflections
12
+
13
+ def create(params)
14
+ self.association_reflections = ::AssociationReflections::Association.new(params)
15
+ super
16
+ end
17
+
18
+ def update(params)
19
+ self.association_reflections = ::AssociationReflections::Association.new(params)
20
+ super
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AssociationReflections
4
+ VERSION = '0.1.0'
5
+ end
data/readme.md ADDED
@@ -0,0 +1,100 @@
1
+ # Association Reflections (Rails)
2
+ This gem lets you access form parameters in your model.
3
+
4
+
5
+ <br/>
6
+
7
+
8
+ ## Why would you want that?
9
+ - See associations marked for deletion
10
+ - See all form parameters
11
+
12
+
13
+ <br/>
14
+
15
+
16
+ ## Installation
17
+ ```ruby
18
+ gem 'association_reflections'
19
+ ```
20
+
21
+
22
+ <br/>
23
+
24
+
25
+ ## Full example
26
+ ```ruby
27
+ class User < ApplicationRecord
28
+ include AssociationReflections::Concern
29
+
30
+ has_many :projects
31
+
32
+ accepts_nested_attributes_for :projects, allow_destroy: true
33
+
34
+ validate :validate_associations
35
+
36
+ private
37
+
38
+ def validate_associations
39
+
40
+ reflection = self.association_reflections
41
+ # => <AssociationReflections::Association>
42
+
43
+ reflection.params
44
+ # {
45
+ # "email" => "",
46
+ # "projects_attributes" => {
47
+ # "0" => {
48
+ # "id" => "1",
49
+ # "name" => "",
50
+ # "_destroy" => "1",
51
+ # "categories_attributes" => {
52
+ # "0" => {
53
+ # "name" => ""
54
+ # }
55
+ # }
56
+ # }
57
+ # }
58
+ # }
59
+
60
+ end
61
+ end
62
+ ```
63
+ ```ruby
64
+ class Project < ApplicationRecord
65
+ belongs_to :user
66
+ has_many :categories
67
+
68
+ accepts_nested_attributes_for :categories, allow_destroy: true
69
+
70
+ validate :validate_associations
71
+
72
+ private
73
+
74
+ def validate_associations
75
+ reflection = self.user.association_reflections
76
+ end
77
+
78
+ end
79
+ ```
80
+ ```ruby
81
+ class Category < ApplicationRecord
82
+ belongs_to :project
83
+
84
+ validate :validate_associations
85
+
86
+ private
87
+
88
+ def validate_associations
89
+ reflection = self.project.user.association_reflections
90
+ end
91
+
92
+ end
93
+ ```
94
+
95
+ <br/>
96
+
97
+
98
+ ## Note
99
+ It must be noted that this only works when using `update` and `create`
100
+ methods.
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: association_reflections
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - EdCordata
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: This gem lets you access form parameters in your model.
28
+ email: EdCordata@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/association_reflections.rb
34
+ - lib/association_reflections/association.rb
35
+ - lib/association_reflections/concern.rb
36
+ - lib/association_reflections/version.rb
37
+ - readme.md
38
+ homepage: https://github.com/EdCordata-Ruby-Gems/association_reflections
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.1.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: This gem lets you access form parameters in your model.
61
+ test_files: []