moorage-xml_protected 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +23 -0
- data/Rakefile +1 -1
- data/lib/xml_protected.rb +11 -6
- metadata +1 -1
data/README.textile
CHANGED
@@ -15,6 +15,9 @@ class Model < ActiveRecord::Base
|
|
15
15
|
end
|
16
16
|
</pre>
|
17
17
|
|
18
|
+
You can also access these attributes from the added class method:
|
19
|
+
|
20
|
+
<code>protected_xml_attributes</code>
|
18
21
|
|
19
22
|
h3. In Conjunction with <code>attr_protected</code>
|
20
23
|
|
@@ -53,6 +56,26 @@ Optionally, to unpack it into your application, just run:
|
|
53
56
|
</pre>
|
54
57
|
|
55
58
|
|
59
|
+
h2. How it works
|
60
|
+
|
61
|
+
Two methods are extended onto your active record class:
|
62
|
+
|
63
|
+
1. <code>xml_protected(*attributes)</code>
|
64
|
+
2. <code>protected_xml_attributes</code>
|
65
|
+
|
66
|
+
1. Adds to the inheritable attribute "xml_protected_attrs" the attributes that are speicified in this call. If this is the first time the method is called, it also aliases the old to_xml, and specified a new one which reads from these xml_protected_attrs
|
67
|
+
|
68
|
+
2. Simply returns the values currently in "xml_protected_attrs".
|
69
|
+
|
70
|
+
One method is included into your active record class, which is pretty self explanatory:
|
71
|
+
|
72
|
+
<pre>
|
73
|
+
def to_xml(options = {})
|
74
|
+
options[:except] ||= []
|
75
|
+
xml_protected_to_xml(options.merge(:except => options[:except].concat(self.class.protected_xml_attributes)))
|
76
|
+
end
|
77
|
+
</pre>
|
78
|
+
|
56
79
|
h2. Copyright & License
|
57
80
|
|
58
81
|
Copyright (c) 2008 ThriveSmart, LLC, released under the MIT license
|
data/Rakefile
CHANGED
data/lib/xml_protected.rb
CHANGED
@@ -6,23 +6,28 @@ module XmlProtected
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ActMethods
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
|
10
|
+
def xml_protected(*attributes)
|
11
|
+
write_inheritable_attribute("xml_protected_attrs", Set.new(attributes.map(&:to_s)) + (protected_xml_attributes || []))
|
12
|
+
|
14
13
|
# only need to define these once on a class
|
15
14
|
unless included_modules.include?(InstanceMethods)
|
16
15
|
alias_method :xml_protected_to_xml, :to_xml
|
17
16
|
include InstanceMethods
|
18
17
|
end
|
19
18
|
end
|
19
|
+
|
20
|
+
# Returns an array of all the attributes that have been protected (excluded) from default to_xml output.
|
21
|
+
def protected_xml_attributes # :nodoc:
|
22
|
+
read_inheritable_attribute("xml_protected_attrs")
|
23
|
+
end
|
24
|
+
|
20
25
|
end
|
21
26
|
|
22
27
|
module InstanceMethods
|
23
28
|
def to_xml(options = {})
|
24
29
|
options[:except] ||= []
|
25
|
-
xml_protected_to_xml(options.merge(:except => options[:except].concat(self.
|
30
|
+
xml_protected_to_xml(options.merge(:except => options[:except].concat(self.class.protected_xml_attributes)))
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|