hobo_fields 2.1.2 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae374e5d1218a6f0810c9f92c324ada484d6b6f7
4
- data.tar.gz: d115ea2e44e137f51a47a20af4e0931c22460242
3
+ metadata.gz: 0cb6f597b6b09d18cc9a657af73a95a6c1b110a9
4
+ data.tar.gz: 4adaa4fce5fb6546fbd44df4b521a72286acd66c
5
5
  SHA512:
6
- metadata.gz: ff3940da7cc52302e0b195453b86c641a9b57f2a6c8dc5e713fa2eed6ec804c7b8dbb4fa17e2fa8b231722df150d72bcaaf6aa62e75cecc5d70fc7ee4b2c61e7
7
- data.tar.gz: 9e79e3f50365f9ff2ae05680dbabffda08b354847a14f6fce1b83403c1f38deaad3cf8c31d961ce185c301289e21efe93f69103f4ec1998abb5e5746d7ded979
6
+ metadata.gz: 2bb5b8f0f133084cddf90702eea6bae7d574cf98fcdfa39c19b5875d601c36d76467a3895bdee6b8dcbf7c5fe43faeaa1dc4015962b9c404e1c1157da1f8104b
7
+ data.tar.gz: 292b1aacb444a563a47d5d40c362749e057e3320e4d7b59d9e962a7960dbf5ce2ae708c8865ef1b549354404f081516b0bc81b420b57ac7b4ef3e3e68cfca209
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem 'rubydoctest', :git => 'git://github.com/bryanlarsen/rubydoctest.git'
4
4
  gem 'rails'
5
5
  gem 'yard'
6
6
  gem 'protected_attributes'
7
+ gem 'responders', '~> 2.0'
7
8
 
8
9
  gemspec :path => "../hobo_support"
9
10
  gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.0
@@ -91,7 +91,7 @@ module Hobo
91
91
  private
92
92
 
93
93
  def migrations_pending?
94
- pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
94
+ pending_migrations = ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations('db/migrate')).pending_migrations
95
95
 
96
96
  if pending_migrations.any?
97
97
  say "You have #{pending_migrations.size} pending migration#{'s' if pending_migrations.size > 1}:"
@@ -1,9 +1,9 @@
1
1
  ActiveRecord::Base.class_eval do
2
- def read_attribute_with_hobo(attr_name)
2
+ def _read_attribute_with_hobo(attr_name)
3
3
  name = attr_name.to_s
4
4
  if self.class.can_wrap_with_hobo_type?(name)
5
5
  attr_name = attr_name.to_sym
6
- val = read_attribute_without_hobo(name)
6
+ val = _read_attribute_without_hobo(name)
7
7
  wrapper_type = self.class.attr_type(attr_name)
8
8
  if HoboFields.can_wrap?(wrapper_type, val)
9
9
  wrapper_type.new(val)
@@ -11,10 +11,10 @@ ActiveRecord::Base.class_eval do
11
11
  val
12
12
  end
13
13
  else
14
- read_attribute_without_hobo(name)
14
+ _read_attribute_without_hobo(name)
15
15
  end
16
16
  end
17
- alias_method_chain :read_attribute, :hobo
17
+ alias_method_chain :_read_attribute, :hobo
18
18
 
19
19
  class << self
20
20
 
@@ -98,7 +98,7 @@ module HoboFields
98
98
  index_options = {}
99
99
  index_options[:name] = options.delete(:index) if options.has_key?(:index)
100
100
  bt = belongs_to_without_field_declarations(name, *args, &block)
101
- refl = reflections[name.to_sym]
101
+ refl = reflections[name.to_s]
102
102
  fkey = refl.foreign_key
103
103
  declare_field(fkey.to_sym, :integer, column_options)
104
104
  if refl.options[:polymorphic]
@@ -157,6 +157,7 @@ module HoboFields
157
157
  validates_presence_of name if :required.in?(args)
158
158
  validates_uniqueness_of name, :allow_nil => !:required.in?(args) if :unique.in?(args)
159
159
 
160
+ # Support for custom validations in Hobo Fields
160
161
  type_class = HoboFields.to_class(type)
161
162
  if type_class && type_class.public_method_defined?("validate")
162
163
  self.validate do |record|
@@ -164,6 +165,7 @@ module HoboFields
164
165
  record.errors.add(name, v) if v.is_a?(String)
165
166
  end
166
167
  end
168
+
167
169
  end
168
170
 
169
171
  def self.add_formatting_for_field(name, type, args)
@@ -209,7 +211,7 @@ module HoboFields
209
211
 
210
212
  attr_types[name] or
211
213
 
212
- if (refl = reflections[name.to_sym])
214
+ if (refl = reflections[name.to_s])
213
215
  if refl.macro.in?([:has_one, :belongs_to]) && !refl.options[:polymorphic]
214
216
  refl.klass
215
217
  else
@@ -1,15 +1,7 @@
1
1
  module HoboFields
2
2
  module Types
3
3
  class HtmlString < RawHtmlString
4
-
5
- include SanitizeHtml
6
-
7
- def self.declared(model, name, options)
8
- model.before_save { |record| record[name] = HoboFields::SanitizeHtml.sanitize(record[name]) }
9
- end
10
-
11
4
  HoboFields.register_type(:html, self)
12
5
  end
13
-
14
6
  end
15
7
  end
@@ -166,7 +166,7 @@ Let's apply that change to the database
166
166
  end
167
167
  >> up, down = Generators::Hobo::Migration::Migrator.run
168
168
  >> up
169
- => "change_column :adverts, :title, :text, :limit => nil"
169
+ => "change_column :adverts, :title, :text"
170
170
  >> down
171
171
  => "change_column :adverts, :title, :string"
172
172
 
@@ -184,7 +184,7 @@ Let's apply that change to the database
184
184
  >> up.split(',').slice(0,3).join(',')
185
185
  => 'change_column :adverts, :title, :string'
186
186
  >> up.split(',').slice(3,2).sort.join(',')
187
- => ' :default => "Untitled", :limit => 255'
187
+ => " :default => \"Untitled\""
188
188
  >> down
189
189
  => "change_column :adverts, :title, :string"
190
190
 
@@ -7,13 +7,6 @@ Our test requires to prepare the testapp:
7
7
 
8
8
  doctest_require: 'prepare_testapp'
9
9
 
10
- >>
11
- ActiveRecord::Migration.create_table :articles do |t|
12
- t.text :body
13
- t.string :status
14
- end
15
- >>
16
-
17
10
  {.hidden}
18
11
 
19
12
  ## `to_html` method
@@ -103,7 +96,7 @@ Provides validation of correct email address format.
103
96
 
104
97
  ### `HoboFields::Types::HtmlString`
105
98
 
106
- `HtmlString` provides no special behavior. The main reason for using this type is that the `to_html` method does not do any html-escaping. Use this for columns that store raw HTML in the database.
99
+ `HtmlString` provides no special behavior. The main reason for using this type is that the `to_html` method does not do any html-escaping. Use this for columns that store raw HTML in the database. Exactly the same as RawHtmlString.
107
100
 
108
101
  # no safety treatments are done by `to_html`.
109
102
  # even if `nasty.to_html` is actually unsafe, it is marked as html_safe.
@@ -113,23 +106,6 @@ Provides validation of correct email address format.
113
106
  >> nasty.to_html.html_safe?
114
107
  => true
115
108
 
116
- >>
117
- class Article < ActiveRecord::Base
118
- fields do
119
- body HoboFields::Types::HtmlString
120
- end
121
- attr_accessible :body
122
- end
123
- >> article = Article.create!(:body => "</div>>>p1<p>p2</p>p3<nasty>p4</nasty>p5&lt;script&gt;p6<script>p7</script>p8")
124
- # some unsafe html fragements are removed on save,
125
- # but there's no guarantees that it is well-formed
126
- >> article.body
127
- => "</div>>>p1<p>p2</p>p3p4p5&lt;script&gt;p6p8"
128
- >> article.body == article.body.to_html
129
- => true
130
- >> article.body.to_html.html_safe?
131
- => true
132
-
133
109
 
134
110
  ### `HoboFields::Types::MarkdownString`
135
111
  `HoboFields::Types::MarkdownString` provides a `to_html` that renders markdown syntax into html. It looks for RDiscount, Kramdown, Maruku or BlueCloth in that order.
@@ -148,7 +124,7 @@ Provides validation of correct email address format.
148
124
  # unsafe html behaviour depends on the parser used.
149
125
  >> markdown = HoboFields::Types::MarkdownString.new("</div>p1<script>p2")
150
126
  >> markdown.to_html
151
- => "<p>&lt;/div&gt;p1</p>\n"
127
+ => "<p>&lt;/div&gt;p1p2</p>\n"
152
128
  # Bluecloth would return
153
129
  # => "<p></div>p1</p>"
154
130
  >> markdown.to_html.html_safe?
@@ -170,7 +146,7 @@ Provides validation of correct email address format.
170
146
  # but there's no guarantees that it is well-formed
171
147
  >> textile = HoboFields::Types::TextileString.new("</div>>>p1<script>p2")
172
148
  >> textile.to_html
173
- => "<p></div>&gt;&gt;p1</p>"
149
+ => "<p>&gt;&gt;p1p2</p></p>"
174
150
  >> textile.to_html.html_safe?
175
151
  => true
176
152
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobo_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Locke
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.2
19
+ version: 2.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.2
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: RedCloth
29
29
  requirement: !ruby/object:Gem::Requirement