hobofields 1.0.2 → 1.0.3
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/Rakefile +5 -4
- data/hobofields.gemspec +80 -0
- data/lib/hobo_fields/model_extensions.rb +10 -6
- data/lib/hobo_fields/serialized_object.rb +1 -1
- data/lib/hobo_fields.rb +22 -7
- data/test/hobofields_api.rdoctest +1 -1
- data/test/rich_types.rdoctest +47 -3
- metadata +12 -11
data/Rakefile
CHANGED
@@ -3,7 +3,11 @@ require 'active_record'
|
|
3
3
|
ActiveRecord::ActiveRecordError # hack for https://rails.lighthouseapp.com/projects/8994/tickets/2577-when-using-activerecordassociations-outside-of-rails-a-nameerror-is-thrown
|
4
4
|
|
5
5
|
RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
|
6
|
-
|
6
|
+
if defined?(Bundler)
|
7
|
+
RUBYDOCTEST = 'bundle exec rubydoctest'
|
8
|
+
else
|
9
|
+
RUBYDOCTEST = ENV['RUBYDOCTEST'] || "#{RUBY} -S rubydoctest"
|
10
|
+
end
|
7
11
|
|
8
12
|
$:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '/../hobofields/lib')
|
9
13
|
$:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '/../hobosupport/lib')
|
@@ -38,6 +42,3 @@ Jeweler::Tasks.new do |gemspec|
|
|
38
42
|
gemspec.add_dependency("hobosupport", ["= #{HoboFields::VERSION}"])
|
39
43
|
end
|
40
44
|
Jeweler::GemcutterTasks.new
|
41
|
-
Jeweler::RubyforgeTasks.new do |rubyforge|
|
42
|
-
rubyforge.doc_task = false
|
43
|
-
end
|
data/hobofields.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hobofields}
|
8
|
+
s.version = "1.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tom Locke"]
|
12
|
+
s.date = %q{2011-02-25}
|
13
|
+
s.email = %q{tom@tomlocke.com}
|
14
|
+
s.files = [
|
15
|
+
"CHANGES.txt",
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.txt",
|
18
|
+
"Rakefile",
|
19
|
+
"hobofields.gemspec",
|
20
|
+
"lib/hobo_fields.rb",
|
21
|
+
"lib/hobo_fields/email_address.rb",
|
22
|
+
"lib/hobo_fields/enum_string.rb",
|
23
|
+
"lib/hobo_fields/field_declaration_dsl.rb",
|
24
|
+
"lib/hobo_fields/field_spec.rb",
|
25
|
+
"lib/hobo_fields/fields_declaration.rb",
|
26
|
+
"lib/hobo_fields/html_string.rb",
|
27
|
+
"lib/hobo_fields/index_spec.rb",
|
28
|
+
"lib/hobo_fields/lifecycle_state.rb",
|
29
|
+
"lib/hobo_fields/markdown_string.rb",
|
30
|
+
"lib/hobo_fields/migration_generator.rb",
|
31
|
+
"lib/hobo_fields/model_extensions.rb",
|
32
|
+
"lib/hobo_fields/password_string.rb",
|
33
|
+
"lib/hobo_fields/raw_html_string.rb",
|
34
|
+
"lib/hobo_fields/raw_markdown_string.rb",
|
35
|
+
"lib/hobo_fields/sanitize_html.rb",
|
36
|
+
"lib/hobo_fields/serialized_object.rb",
|
37
|
+
"lib/hobo_fields/text.rb",
|
38
|
+
"lib/hobo_fields/textile_string.rb",
|
39
|
+
"lib/hobofields.rb",
|
40
|
+
"rails/init.rb",
|
41
|
+
"rails_generators/hobo_migration/USAGE",
|
42
|
+
"rails_generators/hobo_migration/hobo_migration_generator.rb",
|
43
|
+
"rails_generators/hobo_migration/templates/migration.rb",
|
44
|
+
"rails_generators/hobofield_model/USAGE",
|
45
|
+
"rails_generators/hobofield_model/hobofield_model_generator.rb",
|
46
|
+
"rails_generators/hobofield_model/templates/fixtures.yml.erb",
|
47
|
+
"rails_generators/hobofield_model/templates/model.rb.erb",
|
48
|
+
"rails_generators/hobofield_model/templates/test.rb.erb",
|
49
|
+
"script/destroy",
|
50
|
+
"script/generate",
|
51
|
+
"test/hobofields.rdoctest",
|
52
|
+
"test/hobofields_api.rdoctest",
|
53
|
+
"test/migration_generator.rdoctest",
|
54
|
+
"test/migration_generator_primary_key.rdoctest",
|
55
|
+
"test/rich_types.rdoctest",
|
56
|
+
"test/test_generator_helper.rb",
|
57
|
+
"test/test_hobofield_model_generator.rb"
|
58
|
+
]
|
59
|
+
s.homepage = %q{http://hobocentral.net/}
|
60
|
+
s.require_paths = ["lib"]
|
61
|
+
s.rubyforge_project = %q{hobo}
|
62
|
+
s.rubygems_version = %q{1.4.2}
|
63
|
+
s.summary = %q{Rich field types and migration generator for Rails}
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
s.specification_version = 3
|
67
|
+
|
68
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
|
+
s.add_runtime_dependency(%q<rails>, [">= 2.2.2", "< 3.0.0"])
|
70
|
+
s.add_runtime_dependency(%q<hobosupport>, ["= 1.0.3"])
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<rails>, [">= 2.2.2", "< 3.0.0"])
|
73
|
+
s.add_dependency(%q<hobosupport>, ["= 1.0.3"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<rails>, [">= 2.2.2", "< 3.0.0"])
|
77
|
+
s.add_dependency(%q<hobosupport>, ["= 1.0.3"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -22,13 +22,17 @@ module HoboFields
|
|
22
22
|
inheriting_cattr_reader :index_specs => []
|
23
23
|
inheriting_cattr_reader :ignore_indexes => []
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# eval avoids the ruby 1.9.2 "super from singleton method ..." error
|
26
|
+
# see LH#840
|
27
|
+
eval %(
|
28
|
+
def self.inherited(klass)
|
29
|
+
fields do |f|
|
30
|
+
f.field(inheritance_column, :string)
|
31
|
+
end
|
32
|
+
index(inheritance_column)
|
33
|
+
super
|
28
34
|
end
|
29
|
-
|
30
|
-
super
|
31
|
-
end
|
35
|
+
)
|
32
36
|
|
33
37
|
def self.index(fields, options = {})
|
34
38
|
# don't double-index fields
|
data/lib/hobo_fields.rb
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
|
14
14
|
module HoboFields
|
15
15
|
|
16
|
-
VERSION = "1.0.
|
16
|
+
VERSION = "1.0.3"
|
17
17
|
|
18
18
|
extend self
|
19
19
|
|
@@ -68,12 +68,27 @@ module HoboFields
|
|
68
68
|
end
|
69
69
|
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
if Object.instance_method(:initialize).arity!=0
|
72
|
+
# version for Ruby 1.9.
|
73
|
+
def can_wrap?(type, val)
|
74
|
+
col_type = type::COLUMN_TYPE
|
75
|
+
return false if val.blank? && (col_type == :integer || col_type == :float || col_type == :decimal)
|
76
|
+
klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class
|
77
|
+
init_method = type.instance_method(:initialize)
|
78
|
+
[-1,1].include?(init_method.arity) &&
|
79
|
+
init_method.owner != Object.instance_method(:initialize).owner &&
|
80
|
+
!@never_wrap_types.any? { |c| klass <= c }
|
81
|
+
end
|
82
|
+
else
|
83
|
+
# Ruby 1.8. 1.8.6 doesn't include Method#owner. 1.8.7 could use
|
84
|
+
# the 1.9 function, but this one is faster.
|
85
|
+
def can_wrap?(type, val)
|
86
|
+
col_type = type::COLUMN_TYPE
|
87
|
+
return false if val.blank? && (col_type == :integer || col_type == :float || col_type == :decimal)
|
88
|
+
klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class
|
89
|
+
init_method = type.instance_method(:initialize)
|
90
|
+
[-1,1].include?(init_method.arity) && !@never_wrap_types.any? { |c| klass <= c }
|
91
|
+
end
|
77
92
|
end
|
78
93
|
|
79
94
|
|
@@ -169,7 +169,7 @@ In your HoboFields models you can also give type information to "virtual fields"
|
|
169
169
|
|
170
170
|
## Field validations
|
171
171
|
|
172
|
-
HoboFields gives you some shorthands for declaring some common validations right in the field declaration
|
172
|
+
HoboFields gives you some shorthands for declaring some common validations right in the field declaration. HoboFields also supports all of the options supported by the [Rails column declaration](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column)
|
173
173
|
|
174
174
|
### Required fields
|
175
175
|
|
data/test/rich_types.rdoctest
CHANGED
@@ -23,9 +23,9 @@ though we don't need it for this test:
|
|
23
23
|
>> mysql_database = "hobofields_doctest"
|
24
24
|
>> system "mysqladmin #{mysql_login} --force drop #{mysql_database} 2> /dev/null"
|
25
25
|
>> system("mysqladmin #{mysql_login} create #{mysql_database}") or raise "could not create database"
|
26
|
-
>> ActiveRecord::Base.establish_connection(:adapter =>
|
26
|
+
>> ActiveRecord::Base.establish_connection(:adapter => mysql_adapter,
|
27
27
|
:database => mysql_database,
|
28
|
-
:host => "localhost", :
|
28
|
+
:host => "localhost", :username => mysql_user, :password => mysql_password)
|
29
29
|
{.hidden}
|
30
30
|
|
31
31
|
Some load path manipulation you shouldn't need:
|
@@ -165,8 +165,52 @@ Provides validation of correct email address format.
|
|
165
165
|
|
166
166
|
### `HoboFields::PasswordString`
|
167
167
|
|
168
|
-
`HoboFields::PasswordString` provides a simple `to_html` to prevent
|
168
|
+
`HoboFields::PasswordString` provides a simple `to_html` to prevent
|
169
|
+
accidental display of a password. It simply returns "`[password
|
170
|
+
hidden]`". The type is also used to indicate the need for an `<input
|
171
|
+
type='password'>`
|
169
172
|
|
173
|
+
### `HoboFields::Serialized`
|
174
|
+
|
175
|
+
This type lets you store an arbitrary object as serialized text into
|
176
|
+
the database column. You can optionally pass the :class option to
|
177
|
+
restrict the column type.
|
178
|
+
|
179
|
+
>>
|
180
|
+
def migrate(renames={})
|
181
|
+
up, down = HoboFields::MigrationGenerator.run(renames)
|
182
|
+
ActiveRecord::Migration.class_eval(up)
|
183
|
+
ActiveRecord::Base.send(:subclasses).each { |model| model.reset_column_information }
|
184
|
+
[up, down]
|
185
|
+
end
|
186
|
+
{.hidden}
|
187
|
+
|
188
|
+
>>
|
189
|
+
class Vault1 < ActiveRecord::Base
|
190
|
+
fields do
|
191
|
+
content :serialized
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
>> migrate
|
196
|
+
>> Vault1.create!(:content => {:key => "in Vault"})
|
197
|
+
>> Vault1.first.content
|
198
|
+
=> {:key => "in Vault"}
|
199
|
+
|
200
|
+
>>
|
201
|
+
class Vault2 < ActiveRecord::Base
|
202
|
+
fields do
|
203
|
+
content :serialized, :class => Hash
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
>> migrate
|
208
|
+
>> Vault2.create!(:content => {:key => "in Vault"})
|
209
|
+
>> Vault2.first.content
|
210
|
+
=> {:key => "in Vault"}
|
211
|
+
>> Vault2.create!(:content => 17) rescue ActiveRecord::SerializationTypeMismatch
|
212
|
+
>> Vault2.all.size
|
213
|
+
=> 1 # second record not created because of type mismatch
|
170
214
|
|
171
215
|
## Enum Strings
|
172
216
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobofields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tom Locke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-25 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -50,12 +50,12 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
hash:
|
53
|
+
hash: 17
|
54
54
|
segments:
|
55
55
|
- 1
|
56
56
|
- 0
|
57
|
-
-
|
58
|
-
version: 1.0.
|
57
|
+
- 3
|
58
|
+
version: 1.0.3
|
59
59
|
type: :runtime
|
60
60
|
version_requirements: *id002
|
61
61
|
description:
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- LICENSE.txt
|
72
72
|
- README.txt
|
73
73
|
- Rakefile
|
74
|
+
- hobofields.gemspec
|
74
75
|
- lib/hobo_fields.rb
|
75
76
|
- lib/hobo_fields/email_address.rb
|
76
77
|
- lib/hobo_fields/enum_string.rb
|
@@ -114,8 +115,8 @@ homepage: http://hobocentral.net/
|
|
114
115
|
licenses: []
|
115
116
|
|
116
117
|
post_install_message:
|
117
|
-
rdoc_options:
|
118
|
-
|
118
|
+
rdoc_options: []
|
119
|
+
|
119
120
|
require_paths:
|
120
121
|
- lib
|
121
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
140
|
requirements: []
|
140
141
|
|
141
142
|
rubyforge_project: hobo
|
142
|
-
rubygems_version: 1.
|
143
|
+
rubygems_version: 1.4.2
|
143
144
|
signing_key:
|
144
145
|
specification_version: 3
|
145
146
|
summary: Rich field types and migration generator for Rails
|