jcnetdev-acts_as_applyable 0.5 → 0.61
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/README +6 -3
- data/acts_as_applyable.gemspec +2 -2
- data/lib/acts_as_applyable.rb +11 -11
- metadata +2 -2
data/README
CHANGED
|
@@ -16,10 +16,13 @@ New way:
|
|
|
16
16
|
@user.apply(:username, :email, :password, :password_confirmation)
|
|
17
17
|
|
|
18
18
|
In order to enable it, run this on your model
|
|
19
|
-
acts_as_applyable
|
|
20
19
|
|
|
21
|
-
If you want to act similar to attr_accessible, you can
|
|
22
|
-
|
|
20
|
+
If you want to act similar to attr_accessible, you can define a method called applyable_attributes that returns
|
|
21
|
+
the array of fields you want to appy by default.
|
|
22
|
+
|
|
23
|
+
def applyable_fields
|
|
24
|
+
[:name, :email, :password]
|
|
25
|
+
end
|
|
23
26
|
|
|
24
27
|
that way you can run @user.apply and it will use these
|
|
25
28
|
|
data/acts_as_applyable.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'acts_as_applyable'
|
|
3
|
-
s.version = '0.
|
|
4
|
-
s.date = '2008-09-
|
|
3
|
+
s.version = '0.61'
|
|
4
|
+
s.date = '2008-09-23'
|
|
5
5
|
|
|
6
6
|
s.summary = "A better (and safer) way of applying model attributes from your controller params"
|
|
7
7
|
s.description = "Rid yourself of attr_accessible and attr_protected. This plugin allows you to stop using mass assignment, and gives you a more flexible way of interacting with your controller params."
|
data/lib/acts_as_applyable.rb
CHANGED
|
@@ -2,19 +2,11 @@ module ActiveRecord
|
|
|
2
2
|
module Acts
|
|
3
3
|
module Applyable
|
|
4
4
|
def self.included(base)
|
|
5
|
-
base.extend ClassMethods
|
|
6
5
|
base.class_eval do
|
|
7
6
|
include ActiveRecord::Acts::Applyable::InstanceMethods
|
|
8
7
|
end
|
|
9
8
|
end
|
|
10
|
-
|
|
11
|
-
# module ClassMethods
|
|
12
|
-
# def acts_as_applyable(*accessible_attributes)
|
|
13
|
-
# cattr_accessor :accessible_attribute_list
|
|
14
|
-
# self.accessible_attribute_list = accessible_attributes
|
|
15
|
-
# end
|
|
16
|
-
# end
|
|
17
|
-
|
|
9
|
+
|
|
18
10
|
module InstanceMethods
|
|
19
11
|
def params
|
|
20
12
|
@params ||= {}
|
|
@@ -27,11 +19,19 @@ module ActiveRecord
|
|
|
27
19
|
|
|
28
20
|
def apply_set_attributes(*attribute_list)
|
|
29
21
|
self.params.stringify_keys!
|
|
30
|
-
@@accessible_attribute_list ||= []
|
|
31
22
|
|
|
23
|
+
# initialize attribute list if empty
|
|
24
|
+
if attribute_list.empty?
|
|
25
|
+
if self.respond_to?(:applyable_fields)
|
|
26
|
+
attribute_list = self.applyable_fields
|
|
27
|
+
else
|
|
28
|
+
Rails.logger.error("\n\n-------\n\nNO APPLYABLE FIELDS FOUND FOR #{self.class.to_s}\n"+
|
|
29
|
+
"Define a method called applyable_fields and return the array fields to apply by default\n\n-------\n\n")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
32
33
|
# build attributes hash
|
|
33
34
|
attributes = {}
|
|
34
|
-
attribute_list = @@accessible_attribute_list if attribute_list.empty?
|
|
35
35
|
attribute_list.each do |attribute|
|
|
36
36
|
attributes[attribute] = self.params[attribute.to_s]
|
|
37
37
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jcnetdev-acts_as_applyable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: "0.
|
|
4
|
+
version: "0.61"
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RailsJedi
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-09-
|
|
12
|
+
date: 2008-09-23 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|