replace_entities 1.1 → 2.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.
@@ -23,14 +23,24 @@ before they make it into your database.
23
23
 
24
24
  === Installation
25
25
 
26
- Option 1. Load the plugin as a gem
26
+ 1. On rails 2.3
27
27
 
28
- gem install replace_entities
29
- add "config.gem 'replace_entities'" to your environment.rb
28
+ * gem install strip_control_chars
29
+ * add the following to your environment.rb
30
30
 
31
- Option 2. Use the standard Rails plugin install (assuming Rails >= 2.1).
31
+ config.gem 'replace_entities', version => "<2.0"
32
32
 
33
- ./script/plugin install git://github.com/yob/replace_entities.git
33
+ 2. On rails 3
34
+
35
+ * gem install strip_control_chars
36
+ * add the following to your Gemfile
37
+
38
+ gem 'replace_entities', ">=2.0"
39
+
40
+ === Compatibility
41
+
42
+ On rails 2.x you must use version 1.x of this gem. On rails 3.x you must use
43
+ version 2.x of this gem.
34
44
 
35
45
  === Caveats
36
46
 
@@ -1,34 +1,2 @@
1
- require 'htmlentities'
2
-
3
- module ReplaceEntities
4
- # Strips ASCII control chars from attributes before they get saved
5
- def replace_entities!(options = nil)
6
- before_validation do |record|
7
- attributes = ReplaceEntities.narrow(record.attributes, options)
8
- attributes.each do |attr, value|
9
- if value.is_a?(String)
10
- coder = HTMLEntities.new
11
- record[attr] = coder.decode(value)
12
- end
13
- end
14
- end
15
- end
16
-
17
- # Necessary because Rails has removed the narrowing of attributes using :only
18
- # and :except on Base#attributes
19
- def self.narrow(attributes, options)
20
- if options.nil?
21
- attributes
22
- else
23
- if except = options[:except]
24
- except = Array(except).collect { |attribute| attribute.to_s }
25
- attributes.except(*except)
26
- elsif only = options[:only]
27
- only = Array(only).collect { |attribute| attribute.to_s }
28
- attributes.slice(*only)
29
- else
30
- raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"
31
- end
32
- end
33
- end
34
- end
1
+ require 'replace_entities/ar_extend'
2
+ require 'replace_entities/railtie'
@@ -0,0 +1,36 @@
1
+ require 'htmlentities'
2
+
3
+ module ReplaceEntities
4
+ module ArExtend
5
+ # Strips ASCII control chars from attributes before they get saved
6
+ def replace_entities!(options = nil)
7
+ before_validation do |record|
8
+ attributes = ReplaceEntities::ArExtend.narrow(record.attributes, options)
9
+ attributes.each do |attr, value|
10
+ if value.is_a?(String)
11
+ coder = HTMLEntities.new
12
+ record[attr] = coder.decode(value)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ # Necessary because Rails has removed the narrowing of attributes using :only
19
+ # and :except on Base#attributes
20
+ def self.narrow(attributes, options)
21
+ if options.nil?
22
+ attributes
23
+ else
24
+ if except = options[:except]
25
+ except = Array(except).collect { |attribute| attribute.to_s }
26
+ attributes.except(*except)
27
+ elsif only = options[:only]
28
+ only = Array(only).collect { |attribute| attribute.to_s }
29
+ attributes.slice(*only)
30
+ else
31
+ raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ require 'replace_entities'
2
+ require 'rails'
3
+
4
+ module ReplaceEntities
5
+ class Railtie < Rails::Railtie
6
+
7
+ initializer "replace_entities.active_record" do |app|
8
+ if defined?(::ActiveRecord)
9
+ ::ActiveRecord::Base.extend(ReplaceEntities::ArExtend)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -5,9 +5,10 @@ require 'active_record'
5
5
  PLUGIN_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
6
6
 
7
7
  $LOAD_PATH.unshift "#{PLUGIN_ROOT}/lib"
8
- require "#{PLUGIN_ROOT}/init"
8
+ require "replace_entities"
9
9
 
10
10
  class ActiveRecord::Base
11
+ extend ReplaceEntities::ArExtend
11
12
  alias_method :save, :valid?
12
13
  def self.columns()
13
14
  @columns ||= []
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replace_entities
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
- - 1
8
- - 1
9
- version: "1.1"
7
+ - 2
8
+ - 0
9
+ version: "2.0"
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Healy
@@ -37,13 +37,15 @@ dependencies:
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
40
- - - <=
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- hash: 197
42
+ hash: 7712042
43
43
  segments:
44
- - 2
45
- - 99
46
- version: "2.99"
44
+ - 3
45
+ - 0
46
+ - 0
47
+ - rc
48
+ version: 3.0.0.rc
47
49
  type: :runtime
48
50
  version_requirements: *id002
49
51
  description: a small ActiveRecord plugin that removes common HTML entities from attributes
@@ -55,9 +57,9 @@ extensions: []
55
57
  extra_rdoc_files: []
56
58
 
57
59
  files:
58
- - init.rb
59
- - rails/init.rb
60
60
  - lib/replace_entities.rb
61
+ - lib/replace_entities/ar_extend.rb
62
+ - lib/replace_entities/railtie.rb
61
63
  - Rakefile
62
64
  - MIT-LICENSE
63
65
  - README.rdoc
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'replace_entities'
2
- ActiveRecord::Base.extend(ReplaceEntities)
@@ -1,2 +0,0 @@
1
- require 'replace_entities'
2
- ActiveRecord::Base.extend(ReplaceEntities)