hobofields 1.1.0.pre3 → 1.1.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
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
- RUBYDOCTEST = ENV['RUBYDOCTEST'] || "#{RUBY} -S rubydoctest"
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
@@ -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.1.0.pre4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") 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.1.0.pre4"])
71
+ else
72
+ s.add_dependency(%q<rails>, [">= 2.2.2", "< 3.0.0"])
73
+ s.add_dependency(%q<hobosupport>, ["= 1.1.0.pre4"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<rails>, [">= 2.2.2", "< 3.0.0"])
77
+ s.add_dependency(%q<hobosupport>, ["= 1.1.0.pre4"])
78
+ end
79
+ end
80
+
data/lib/hobo_fields.rb CHANGED
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  module HoboFields
15
15
 
16
- VERSION = "1.1.0.pre3"
16
+ VERSION = "1.1.0.pre4"
17
17
 
18
18
  extend self
19
19
 
@@ -68,12 +68,27 @@ module HoboFields
68
68
  end
69
69
 
70
70
 
71
- def can_wrap?(type, val)
72
- col_type = type::COLUMN_TYPE
73
- return false if val.blank? && (col_type == :integer || col_type == :float || col_type == :decimal)
74
- klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class
75
- arity = type.instance_method(:initialize).arity
76
- (arity == 1 || arity == -1) && !@never_wrap_types.any? { |c| klass <= c }
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
 
@@ -5,7 +5,7 @@ module HoboFields
5
5
  COLUMN_TYPE = :text
6
6
 
7
7
  def self.declared(model, name, options)
8
- model.serialize name, options.delete(:class)
8
+ model.serialize name, options.delete(:class) || Object
9
9
  end
10
10
 
11
11
  HoboFields.register_type(:serialized, self)
@@ -715,9 +715,8 @@ Because it will be quite common for people not to have both [column_comments](ht
715
715
  end
716
716
  end
717
717
  >> up, down = HoboFields::MigrationGenerator.run
718
- >> up
719
- => "change_column :products, :name, :string, :limit => 255, :comment => \"Short namex\""
720
-
718
+ >> up.split(',').slice(3,2).sort.join(',')
719
+ => " :comment => \"Short namex\", :limit => 255"
721
720
 
722
721
  Cleanup
723
722
  {.hidden}
@@ -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 => "mysql",
26
+ >> ActiveRecord::Base.establish_connection(:adapter => mysql_adapter,
27
27
  :database => mysql_database,
28
- :host => "localhost", :user => mysql_user, :password => mysql_password)
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 accidental display of a password. It simply returns "`[password hidden]`". The type is also used to indicate the need for an `<input type='password'>`
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,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobofields
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1876988186
5
- prerelease: true
4
+ hash: 1923831953
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 0
10
- - pre3
11
- version: 1.1.0.pre3
10
+ - pre
11
+ - 4
12
+ version: 1.1.0.pre4
12
13
  platform: ruby
13
14
  authors:
14
15
  - Tom Locke
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-01-16 00:00:00 -05:00
20
+ date: 2011-02-25 00:00:00 -05:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -51,13 +52,14 @@ dependencies:
51
52
  requirements:
52
53
  - - "="
53
54
  - !ruby/object:Gem::Version
54
- hash: -1876988186
55
+ hash: 1923831953
55
56
  segments:
56
57
  - 1
57
58
  - 1
58
59
  - 0
59
- - pre3
60
- version: 1.1.0.pre3
60
+ - pre
61
+ - 4
62
+ version: 1.1.0.pre4
61
63
  type: :runtime
62
64
  version_requirements: *id002
63
65
  description:
@@ -73,6 +75,7 @@ files:
73
75
  - LICENSE.txt
74
76
  - README.txt
75
77
  - Rakefile
78
+ - hobofields.gemspec
76
79
  - lib/hobo_fields.rb
77
80
  - lib/hobo_fields/email_address.rb
78
81
  - lib/hobo_fields/enum_string.rb
@@ -116,8 +119,8 @@ homepage: http://hobocentral.net/
116
119
  licenses: []
117
120
 
118
121
  post_install_message:
119
- rdoc_options:
120
- - --charset=UTF-8
122
+ rdoc_options: []
123
+
121
124
  require_paths:
122
125
  - lib
123
126
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -143,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
146
  requirements: []
144
147
 
145
148
  rubyforge_project: hobo
146
- rubygems_version: 1.3.7
149
+ rubygems_version: 1.4.2
147
150
  signing_key:
148
151
  specification_version: 3
149
152
  summary: Rich field types and migration generator for Rails