hobofields 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,11 @@
1
- require 'echoe'
1
+ require 'rubygems'
2
+ require 'activerecord'
3
+ ActiveRecord::ActiveRecordError # hack for https://rails.lighthouseapp.com/projects/8994/tickets/2577-when-using-activerecordassociations-outside-of-rails-a-nameerror-is-thrown
4
+
5
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '/../hobofields/lib')
6
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '/../hobosupport/lib')
7
+ require 'hobosupport'
8
+ require 'hobofields'
2
9
 
3
10
  namespace "test" do
4
11
  desc "Run the doctests"
@@ -14,17 +21,23 @@ namespace "test" do
14
21
  end
15
22
  end
16
23
 
17
- Echoe.new('hobofields') do |p|
18
- p.author = "Tom Locke"
19
- p.email = "tom@tomlocke.com"
20
- p.summary = "Rich field types and migration generator for Rails"
21
- p.url = "http://hobocentral.net/hobofields"
22
- p.project = "hobo"
23
-
24
- p.changelog = "CHANGES.txt"
25
- p.version = "0.8.8"
26
-
27
- p.dependencies = ['hobosupport =0.8.8', 'rails >=2.2.2']
28
- p.development_dependencies = []
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |gemspec|
27
+ gemspec.version = HoboFields::VERSION
28
+ gemspec.name = "hobofields"
29
+ gemspec.email = "tom@tomlocke.com"
30
+ gemspec.summary = "Rich field types and migration generator for Rails"
31
+ gemspec.homepage = "http://hobocentral.net/"
32
+ gemspec.authors = ["Tom Locke"]
33
+ gemspec.rubyforge_project = "hobofields"
34
+ gemspec.add_dependency("rails", [">= 2.2.2"])
35
+ gemspec.add_dependency("hobosupport", ["= #{HoboFields::VERSION}"])
36
+ end
37
+ Jeweler::GemcutterTasks.new
38
+ Jeweler::RubyforgeTasks.new do |rubyforge|
39
+ rubyforge.doc_task = "rdoc"
40
+ end
41
+ rescue LoadError
42
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
29
43
  end
30
-
@@ -108,6 +108,7 @@ module HoboFields
108
108
  def self.declare_field(name, type, *args)
109
109
  options = args.extract_options!
110
110
  try.field_added(name, type, args, options)
111
+ add_formatting_for_field(name, type, args)
111
112
  add_validations_for_field(name, type, args)
112
113
  declare_attr_type(name, type, options) unless HoboFields.plain_type?(type)
113
114
  field_specs[name] = FieldSpec.new(self, name, type, options)
@@ -131,6 +132,16 @@ module HoboFields
131
132
  end
132
133
 
133
134
 
135
+ def self.add_formatting_for_field(name, type, args)
136
+ type_class = HoboFields.to_class(type)
137
+ if type_class && "format".in?(type_class.instance_methods)
138
+ self.before_validation do |record|
139
+ record.send("#{name}=", record.send(name)._?.format)
140
+ end
141
+ end
142
+ end
143
+
144
+
134
145
  # Extended version of the acts_as_list declaration that
135
146
  # automatically delcares the 'position' field
136
147
  def self.acts_as_list_with_field_declaration(options = {})
data/lib/hobo_fields.rb CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  module HoboFields
11
11
 
12
- VERSION = "0.8.8"
12
+ VERSION = "0.8.9"
13
13
 
14
14
  extend self
15
15
 
@@ -0,0 +1,94 @@
1
+ -*- indent-tabs-mode:nil; -*-
2
+
3
+ # HoboFields - Migration Generator
4
+
5
+ Note that these doctests are good tests but not such good docs. The migration generator doesn't really fit well with the doctest concept of a single IRB session. As you'll see, there's a lot of jumping-through-hoops and doing stuff that no normal user of the migration generator would ever do.
6
+
7
+ Firstly, in order to test the migration generator outside of a full Rails stack, there's a few things we need to do. First off we need to configure ActiveSupport for auto-loading
8
+
9
+ >> require 'rubygems'
10
+ >> require 'activesupport'
11
+ >> require 'activerecord'
12
+
13
+ We also need to get ActiveRecord set up with a database connection
14
+
15
+ >> mysql_database = "hobofields_doctest"
16
+ >> system "mysqladmin --force drop #{mysql_database} 2> /dev/null"
17
+ >> system("mysqladmin create #{mysql_database}") or raise "could not create database"
18
+ >> ActiveRecord::Base.establish_connection(:adapter => "mysql",
19
+ :database => mysql_database,
20
+ :host => "localhost")
21
+
22
+ Some load path manipulation you shouldn't need:
23
+
24
+ >> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../hobofields/lib')
25
+ >> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../hobosupport/lib')
26
+
27
+ And we'll require:
28
+
29
+ >> require 'hobosupport'
30
+ >> require 'hobofields'
31
+
32
+ OK we're ready to get going.
33
+
34
+ We'll define a method to make that easier next time
35
+
36
+ >>
37
+ def migrate(renames={})
38
+ up, down = HoboFields::MigrationGenerator.run(renames)
39
+ puts up
40
+ ActiveRecord::Migration.class_eval(up)
41
+ ActiveRecord::Base.send(:subclasses).each { |model| model.reset_column_information }
42
+ [up, down]
43
+ end
44
+
45
+ ## Alternate Primary Keys
46
+
47
+ ### create
48
+
49
+ >>
50
+ class Foo < ActiveRecord::Base
51
+ fields do
52
+ end
53
+ set_primary_key "foo_id"
54
+ end
55
+ >> up, down = HoboFields::MigrationGenerator.run
56
+ >> up
57
+ =>
58
+ "create_table :foos, :primary_key => :foo_id do |t|
59
+ end"
60
+ >> migrate
61
+
62
+ ### migrate from
63
+
64
+ >>
65
+ class Foo < ActiveRecord::Base
66
+ set_primary_key "id"
67
+ end
68
+ >> up, down = HoboFields::MigrationGenerator.run({:foos => {:foo_id => :id}})
69
+ >> up
70
+
71
+ => "rename_column :foos, :foo_id, :id"
72
+ >> migrate({:foos => {:foo_id => :id}})
73
+
74
+ ### migrate to
75
+
76
+ >>
77
+ class Foo < ActiveRecord::Base
78
+ set_primary_key "foo_id"
79
+ end
80
+ >> up, down = HoboFields::MigrationGenerator.run({:foos => {:id => :foo_id}})
81
+ >> up
82
+
83
+ => "rename_column :foos, :id, :foo_id"
84
+ >> migrate({:foos => {:id => :foo_id}})
85
+
86
+ ### ensure it doesn't cause further migrations
87
+
88
+ >> up, down = HoboFields::MigrationGenerator.run
89
+ >> up
90
+ => ""
91
+
92
+ ## Cleanup
93
+
94
+ >> system "mysqladmin --force drop #{mysql_database} 2> /dev/null"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobofields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Locke
@@ -9,59 +9,45 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-24 00:00:00 -04:00
12
+ date: 2009-10-14 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: hobosupport
16
+ name: rails
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "="
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.8.8
23
+ version: 2.2.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: rails
26
+ name: hobosupport
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.2
33
+ version: 0.8.9
34
34
  version:
35
- description: Rich field types and migration generator for Rails
35
+ description:
36
36
  email: tom@tomlocke.com
37
37
  executables: []
38
38
 
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
- - lib/hobo_fields/email_address.rb
43
- - lib/hobo_fields/enum_string.rb
44
- - lib/hobo_fields/field_declaration_dsl.rb
45
- - lib/hobo_fields/field_spec.rb
46
- - lib/hobo_fields/fields_declaration.rb
47
- - lib/hobo_fields/html_string.rb
48
- - lib/hobo_fields/markdown_string.rb
49
- - lib/hobo_fields/migration_generator.rb
50
- - lib/hobo_fields/model_extensions.rb
51
- - lib/hobo_fields/password_string.rb
52
- - lib/hobo_fields/raw_html_string.rb
53
- - lib/hobo_fields/raw_markdown_string.rb
54
- - lib/hobo_fields/sanitize_html.rb
55
- - lib/hobo_fields/serialized_object.rb
56
- - lib/hobo_fields/text.rb
57
- - lib/hobo_fields/textile_string.rb
58
- - lib/hobo_fields.rb
59
- - lib/hobofields.rb
60
42
  - LICENSE.txt
61
43
  - README.txt
62
44
  files:
63
45
  - CHANGES.txt
46
+ - LICENSE.txt
47
+ - README.txt
48
+ - Rakefile
64
49
  - init.rb
50
+ - lib/hobo_fields.rb
65
51
  - lib/hobo_fields/email_address.rb
66
52
  - lib/hobo_fields/enum_string.rb
67
53
  - lib/hobo_fields/field_declaration_dsl.rb
@@ -78,38 +64,30 @@ files:
78
64
  - lib/hobo_fields/serialized_object.rb
79
65
  - lib/hobo_fields/text.rb
80
66
  - lib/hobo_fields/textile_string.rb
81
- - lib/hobo_fields.rb
82
67
  - lib/hobofields.rb
83
- - LICENSE.txt
84
- - Manifest
85
68
  - rails_generators/hobo_migration/hobo_migration_generator.rb
86
69
  - rails_generators/hobo_migration/templates/migration.rb
70
+ - rails_generators/hobofield_model/USAGE
87
71
  - rails_generators/hobofield_model/hobofield_model_generator.rb
88
72
  - rails_generators/hobofield_model/templates/fixtures.yml.erb
89
73
  - rails_generators/hobofield_model/templates/model.rb.erb
90
74
  - rails_generators/hobofield_model/templates/test.rb.erb
91
- - rails_generators/hobofield_model/USAGE
92
- - Rakefile
93
- - README.txt
94
75
  - script/destroy
95
76
  - script/generate
96
77
  - test/hobofields.rdoctest
97
78
  - test/hobofields_api.rdoctest
98
79
  - test/migration_generator.rdoctest
80
+ - test/migration_generator_primary_key.rdoctest
99
81
  - test/rich_types.rdoctest
100
82
  - test/test_generator_helper.rb
101
83
  - test/test_hobofield_model_generator.rb
102
- - hobofields.gemspec
103
84
  has_rdoc: true
104
- homepage: http://hobocentral.net/hobofields
85
+ homepage: http://hobocentral.net/
86
+ licenses: []
87
+
105
88
  post_install_message:
106
89
  rdoc_options:
107
- - --line-numbers
108
- - --inline-source
109
- - --title
110
- - Hobofields
111
- - --main
112
- - README.txt
90
+ - --charset=UTF-8
113
91
  require_paths:
114
92
  - lib
115
93
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -122,15 +100,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
100
  requirements:
123
101
  - - ">="
124
102
  - !ruby/object:Gem::Version
125
- version: "1.2"
103
+ version: "0"
126
104
  version:
127
105
  requirements: []
128
106
 
129
- rubyforge_project: hobo
130
- rubygems_version: 1.3.1
107
+ rubyforge_project: hobofields
108
+ rubygems_version: 1.3.5
131
109
  signing_key:
132
- specification_version: 2
110
+ specification_version: 3
133
111
  summary: Rich field types and migration generator for Rails
134
- test_files:
135
- - test/test_generator_helper.rb
136
- - test/test_hobofield_model_generator.rb
112
+ test_files: []
113
+
data/Manifest DELETED
@@ -1,39 +0,0 @@
1
- CHANGES.txt
2
- init.rb
3
- lib/hobo_fields/email_address.rb
4
- lib/hobo_fields/enum_string.rb
5
- lib/hobo_fields/field_declaration_dsl.rb
6
- lib/hobo_fields/field_spec.rb
7
- lib/hobo_fields/fields_declaration.rb
8
- lib/hobo_fields/html_string.rb
9
- lib/hobo_fields/markdown_string.rb
10
- lib/hobo_fields/migration_generator.rb
11
- lib/hobo_fields/model_extensions.rb
12
- lib/hobo_fields/password_string.rb
13
- lib/hobo_fields/raw_html_string.rb
14
- lib/hobo_fields/raw_markdown_string.rb
15
- lib/hobo_fields/sanitize_html.rb
16
- lib/hobo_fields/serialized_object.rb
17
- lib/hobo_fields/text.rb
18
- lib/hobo_fields/textile_string.rb
19
- lib/hobo_fields.rb
20
- lib/hobofields.rb
21
- LICENSE.txt
22
- Manifest
23
- rails_generators/hobo_migration/hobo_migration_generator.rb
24
- rails_generators/hobo_migration/templates/migration.rb
25
- rails_generators/hobofield_model/hobofield_model_generator.rb
26
- rails_generators/hobofield_model/templates/fixtures.yml.erb
27
- rails_generators/hobofield_model/templates/model.rb.erb
28
- rails_generators/hobofield_model/templates/test.rb.erb
29
- rails_generators/hobofield_model/USAGE
30
- Rakefile
31
- README.txt
32
- script/destroy
33
- script/generate
34
- test/hobofields.rdoctest
35
- test/hobofields_api.rdoctest
36
- test/migration_generator.rdoctest
37
- test/rich_types.rdoctest
38
- test/test_generator_helper.rb
39
- test/test_hobofield_model_generator.rb
data/hobofields.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{hobofields}
5
- s.version = "0.8.8"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Tom Locke"]
9
- s.date = %q{2009-06-24}
10
- s.description = %q{Rich field types and migration generator for Rails}
11
- s.email = %q{tom@tomlocke.com}
12
- s.extra_rdoc_files = ["lib/hobo_fields/email_address.rb", "lib/hobo_fields/enum_string.rb", "lib/hobo_fields/field_declaration_dsl.rb", "lib/hobo_fields/field_spec.rb", "lib/hobo_fields/fields_declaration.rb", "lib/hobo_fields/html_string.rb", "lib/hobo_fields/markdown_string.rb", "lib/hobo_fields/migration_generator.rb", "lib/hobo_fields/model_extensions.rb", "lib/hobo_fields/password_string.rb", "lib/hobo_fields/raw_html_string.rb", "lib/hobo_fields/raw_markdown_string.rb", "lib/hobo_fields/sanitize_html.rb", "lib/hobo_fields/serialized_object.rb", "lib/hobo_fields/text.rb", "lib/hobo_fields/textile_string.rb", "lib/hobo_fields.rb", "lib/hobofields.rb", "LICENSE.txt", "README.txt"]
13
- s.files = ["CHANGES.txt", "init.rb", "lib/hobo_fields/email_address.rb", "lib/hobo_fields/enum_string.rb", "lib/hobo_fields/field_declaration_dsl.rb", "lib/hobo_fields/field_spec.rb", "lib/hobo_fields/fields_declaration.rb", "lib/hobo_fields/html_string.rb", "lib/hobo_fields/markdown_string.rb", "lib/hobo_fields/migration_generator.rb", "lib/hobo_fields/model_extensions.rb", "lib/hobo_fields/password_string.rb", "lib/hobo_fields/raw_html_string.rb", "lib/hobo_fields/raw_markdown_string.rb", "lib/hobo_fields/sanitize_html.rb", "lib/hobo_fields/serialized_object.rb", "lib/hobo_fields/text.rb", "lib/hobo_fields/textile_string.rb", "lib/hobo_fields.rb", "lib/hobofields.rb", "LICENSE.txt", "Manifest", "rails_generators/hobo_migration/hobo_migration_generator.rb", "rails_generators/hobo_migration/templates/migration.rb", "rails_generators/hobofield_model/hobofield_model_generator.rb", "rails_generators/hobofield_model/templates/fixtures.yml.erb", "rails_generators/hobofield_model/templates/model.rb.erb", "rails_generators/hobofield_model/templates/test.rb.erb", "rails_generators/hobofield_model/USAGE", "Rakefile", "README.txt", "script/destroy", "script/generate", "test/hobofields.rdoctest", "test/hobofields_api.rdoctest", "test/migration_generator.rdoctest", "test/rich_types.rdoctest", "test/test_generator_helper.rb", "test/test_hobofield_model_generator.rb", "hobofields.gemspec"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://hobocentral.net/hobofields}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hobofields", "--main", "README.txt"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{hobo}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %q{Rich field types and migration generator for Rails}
21
- s.test_files = ["test/test_generator_helper.rb", "test/test_hobofield_model_generator.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<hobosupport>, ["= 0.8.8"])
29
- s.add_runtime_dependency(%q<rails>, [">= 2.2.2"])
30
- else
31
- s.add_dependency(%q<hobosupport>, ["= 0.8.8"])
32
- s.add_dependency(%q<rails>, [">= 2.2.2"])
33
- end
34
- else
35
- s.add_dependency(%q<hobosupport>, ["= 0.8.8"])
36
- s.add_dependency(%q<rails>, [">= 2.2.2"])
37
- end
38
- end