ActsAsEscaped 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2006-11-13
2
+
3
+ * Initial Release
4
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/acts_as_escaped
6
+ lib/acts_as_escaped.rb
7
+ test/test_acts_as_escaped.rb
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ ActsAsEscaped
2
+ by Adocca AB
3
+ http://www.adocca.com
4
+
5
+ == DESCRIPTION:
6
+
7
+ Automatically escapes access to AR attributes
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Hash access to attributes bypasses acts_as_cached
12
+
13
+ == SYNOPSYS:
14
+
15
+ Just add a method call in your AR class body: acts_as_cached
16
+
17
+ == REQUIREMENTS:
18
+
19
+ Rails 1.1.2
20
+
21
+ == INSTALL:
22
+
23
+ sudo gem install acts_as_escaped
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2006 Adocca AB
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/acts_as_escaped.rb'
6
+
7
+ Hoe.new('ActsAsEscaped', Adocca::Acts::ActsAsEscaped::VERSION) do |p|
8
+ p.rubyforge_name = 'adocca_plugins'
9
+ p.summary = 'Rails plugin to automagically escape string output from your models.'
10
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
11
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ end
14
+
15
+ # vim: syntax=Ruby
File without changes
@@ -0,0 +1,83 @@
1
+ require 'active_record'
2
+ require 'cgi'
3
+
4
+ module Adocca
5
+ module Acts
6
+ module ActsAsEscaped
7
+ VERSION = "0.0.1"
8
+
9
+ def self.append_features(base)
10
+ super
11
+ base.extend(ClassMethods)
12
+ end
13
+
14
+ module ClassMethods
15
+ def acts_as_escaped
16
+ class_eval do
17
+ extend Adocca::Acts::ActsAsEscaped::SingletonMethods
18
+ end
19
+ include Adocca::Acts::ActsAsEscaped::InstanceMethods
20
+ end
21
+ end
22
+ module SingletonMethods
23
+ end
24
+ module InstanceMethods
25
+ #
26
+ # does the same thing as the normal method_missing, except
27
+ # it uses the newly defined read method instead of read_attribute after having defined
28
+ # the read methods
29
+ #
30
+ def method_missing(method_id, *args, &block)
31
+ method_name = method_id.to_s
32
+ if @attributes.include?(method_name) or
33
+ (md = /\?$/.match(method_name) and
34
+ @attributes.include?(method_name = md.pre_match))
35
+ if self.class.read_methods.empty? && self.class.generate_read_methods
36
+ define_read_methods
37
+ self.send(method_name)
38
+ else
39
+ md ? query_attribute(method_name) : read_attribute(method_name)
40
+ end
41
+ elsif self.class.primary_key.to_s == method_name
42
+ id
43
+ elsif md = /(=|_before_type_cast)$/.match(method_name)
44
+ attribute_name, method_type = md.pre_match, md.to_s
45
+ if @attributes.include?(attribute_name)
46
+ case method_type
47
+ when '='
48
+ write_attribute(attribute_name, args.first)
49
+ when '_before_type_cast'
50
+ read_attribute_before_type_cast(attribute_name)
51
+ end
52
+ else
53
+ super
54
+ end
55
+ else
56
+ super
57
+ end
58
+ end
59
+ #
60
+ # Does the same thing as the normal define_read_method, but
61
+ # it also does escapeHTML/word splitting on all text columns
62
+ #
63
+ def define_read_method(symbol, attr_name, column)
64
+ if column.nil? || column.type_cast_code('v').nil?
65
+ access_code = "@attributes['#{attr_name}']"
66
+ else
67
+ access_code = "(v=@attributes['#{attr_name}']) && #{column.type_cast_code('v')}"
68
+ end
69
+ access_code = "(v2 = (#{access_code})) && CGI.escapeHTML(v2.to_s)" if (!column.nil? && column.text?)
70
+
71
+ unless attr_name.to_s == self.class.primary_key.to_s
72
+ access_code = access_code.insert(0, "raise NoMethodError, 'missing attribute: #{attr_name}', caller unless @attributes.has_key?('#{attr_name}'); ")
73
+ self.class.read_methods << attr_name
74
+ end
75
+
76
+ evaluate_read_method attr_name, "def #{symbol}; #{access_code}; end"
77
+ end
78
+ end # of module InstanceMethods
79
+ end
80
+ end
81
+ end
82
+
83
+ ActiveRecord::Base.send(:include, Adocca::Acts::ActsAsEscaped)
File without changes
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: ActsAsEscaped
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2006-11-13 00:00:00 +01:00
8
+ summary: Rails plugin to automagically escape string output from your models.
9
+ require_paths:
10
+ - lib
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: " by Adocca AB"
13
+ rubyforge_project: adocca_plugins
14
+ description: "== FEATURES/PROBLEMS: Hash access to attributes bypasses acts_as_cached == SYNOPSYS: Just add a method call in your AR class body: acts_as_cached == REQUIREMENTS:"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ryan Davis
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/acts_as_escaped
37
+ - lib/acts_as_escaped.rb
38
+ - test/test_acts_as_escaped.rb
39
+ test_files:
40
+ - test/test_acts_as_escaped.rb
41
+ rdoc_options: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ executables:
46
+ - acts_as_escaped
47
+ extensions: []
48
+
49
+ requirements: []
50
+
51
+ dependencies:
52
+ - !ruby/object:Gem::Dependency
53
+ name: hoe
54
+ version_requirement:
55
+ version_requirements: !ruby/object:Gem::Version::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.1.4
60
+ version: