hobofields 0.7.5 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,6 +1,4 @@
1
1
  CHANGES.txt
2
- generators/hobo_migration/hobo_migration_generator.rb
3
- generators/hobo_migration/templates/migration.rb
4
2
  init.rb
5
3
  lib/hobo_fields/email_address.rb
6
4
  lib/hobo_fields/enum_string.rb
@@ -17,9 +15,20 @@ lib/hobo_fields/textile_string.rb
17
15
  lib/hobo_fields.rb
18
16
  lib/hobofields.rb
19
17
  LICENSE.txt
18
+ Manifest
19
+ rails_generators/hobo_migration/hobo_migration_generator.rb
20
+ rails_generators/hobo_migration/templates/migration.rb
21
+ rails_generators/hobofield_model/hobofield_model_generator.rb
22
+ rails_generators/hobofield_model/templates/fixtures.yml.erb
23
+ rails_generators/hobofield_model/templates/model.rb.erb
24
+ rails_generators/hobofield_model/templates/test.rb.erb
25
+ rails_generators/hobofield_model/USAGE
20
26
  README.txt
27
+ script/destroy
28
+ script/generate
21
29
  test/hobofields.rdoctest
22
30
  test/hobofields_api.rdoctest
23
31
  test/migration_generator.rdoctest
24
32
  test/rich_types.rdoctest
25
- Manifest
33
+ test/test_generator_helper.rb
34
+ test/test_hobofield_model_generator.rb
data/hobofields.gemspec CHANGED
@@ -1,27 +1,39 @@
1
1
 
2
- # Gem::Specification for Hobofields-0.7.5
2
+ # Gem::Specification for Hobofields-0.8
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{hobofields}
7
- s.version = "0.7.5"
8
-
9
- s.specification_version = 2 if s.respond_to? :specification_version=
7
+ s.version = "0.8"
10
8
 
11
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
10
  s.authors = ["Tom Locke"]
13
- s.date = %q{2008-04-18}
11
+ s.date = %q{2008-09-03}
14
12
  s.description = %q{Rich field types and migration generator for Rails}
15
13
  s.email = %q{tom@tomlocke.com}
16
14
  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/text.rb", "lib/hobo_fields/textile_string.rb", "lib/hobo_fields.rb", "lib/hobofields.rb", "LICENSE.txt", "README.txt"]
17
- s.files = ["CHANGES.txt", "generators/hobo_migration/hobo_migration_generator.rb", "generators/hobo_migration/templates/migration.rb", "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/text.rb", "lib/hobo_fields/textile_string.rb", "lib/hobo_fields.rb", "lib/hobofields.rb", "LICENSE.txt", "README.txt", "test/hobofields.rdoctest", "test/hobofields_api.rdoctest", "test/migration_generator.rdoctest", "test/rich_types.rdoctest", "Manifest", "hobofields.gemspec"]
15
+ 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/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", "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"]
18
16
  s.has_rdoc = true
19
17
  s.homepage = %q{http://hobocentral.net/hobofields}
20
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hobofields", "--main", "README.txt"]
21
19
  s.require_paths = ["lib"]
22
20
  s.rubyforge_project = %q{hobo}
23
- s.rubygems_version = %q{1.0.1}
21
+ s.rubygems_version = %q{1.2.0}
24
22
  s.summary = %q{Rich field types and migration generator for Rails}
23
+ s.test_files = ["test/test_generator_helper.rb", "test/test_hobofield_model_generator.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if current_version >= 3 then
30
+ s.add_runtime_dependency(%q<hobosupport>, [">= 0.8"])
31
+ else
32
+ s.add_dependency(%q<hobosupport>, [">= 0.8"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<hobosupport>, [">= 0.8"])
36
+ end
25
37
  end
26
38
 
27
39
 
@@ -35,8 +47,10 @@ end
35
47
  # p.summary = "Rich field types and migration generator for Rails"
36
48
  # p.url = "http://hobocentral.net/hobofields"
37
49
  # p.project = "hobo"
38
- #
50
+ #
39
51
  # p.changelog = "CHANGES.txt"
40
- # p.version = "0.7.5"
52
+ # p.version = "0.8"
53
+ #
54
+ # p.dependencies = ['hobosupport >=0.8']
41
55
  # end
42
56
  #
@@ -1,18 +1,18 @@
1
1
  module HoboFields
2
-
2
+
3
3
  class EmailAddress < String
4
-
4
+
5
5
  COLUMN_TYPE = :string
6
-
6
+
7
7
  def validate
8
8
  "is not valid" unless valid? || blank?
9
9
  end
10
-
10
+
11
11
  def valid?
12
12
  self =~ /^\s*([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*$/i
13
13
  end
14
-
15
- def to_html
14
+
15
+ def to_html(xmldoctype = true)
16
16
  self
17
17
  end
18
18
 
@@ -1,28 +1,28 @@
1
1
  require 'hobo_fields/field_declaration_dsl'
2
2
 
3
3
  module HoboFields
4
-
4
+
5
5
  class EnumString < String
6
-
6
+
7
7
  module DeclarationHelper
8
-
8
+
9
9
  def enum_string(*values)
10
10
  EnumString.for(*values)
11
11
  end
12
-
12
+
13
13
  end
14
-
14
+
15
15
  FieldDeclarationDsl.send(:include, DeclarationHelper)
16
16
 
17
-
18
- class << self
19
-
17
+
18
+ class << self
19
+
20
20
  def with_values(*values)
21
21
  @values = values.*.to_s
22
22
  end
23
-
23
+
24
24
  attr_accessor :values
25
-
25
+
26
26
  def for(*values)
27
27
  values = values.*.to_s
28
28
  c = Class.new(EnumString) do
@@ -37,20 +37,20 @@ module HoboFields
37
37
  c.with_values(*values)
38
38
  c
39
39
  end
40
-
40
+
41
41
  def inspect
42
42
  name.blank? ? "#<EnumString #{(values || []) * ' '}>" : name
43
43
  end
44
44
  alias_method :to_s, :inspect
45
-
45
+
46
46
  end
47
47
 
48
48
  COLUMN_TYPE = :string
49
-
49
+
50
50
  def validate
51
51
  "must be one of #{self.class.values * ', '}" unless self.in?(self.class.values)
52
52
  end
53
-
53
+
54
54
  def ==(other)
55
55
  if other.is_a?(Symbol)
56
56
  super(other.to_s)
@@ -58,7 +58,7 @@ module HoboFields
58
58
  super
59
59
  end
60
60
  end
61
-
61
+
62
62
  end
63
-
63
+
64
64
  end
@@ -1,29 +1,29 @@
1
1
  module HoboFields
2
-
2
+
3
3
  class FieldDeclarationDsl < BlankSlate
4
-
4
+
5
5
  def initialize(model)
6
6
  @model = model
7
7
  end
8
-
8
+
9
9
  attr_reader :model
10
-
11
-
10
+
11
+
12
12
  def timestamps
13
13
  field(:created_at, :datetime)
14
14
  field(:updated_at, :datetime)
15
15
  end
16
-
17
-
16
+
17
+
18
18
  def field(name, type, *args)
19
19
  @model.declare_field(name, type, *args)
20
20
  end
21
-
22
-
21
+
22
+
23
23
  def method_missing(name, *args)
24
24
  field(name, *args)
25
25
  end
26
-
26
+
27
27
  end
28
-
28
+
29
29
  end
@@ -1,9 +1,9 @@
1
1
  module HoboFields
2
-
2
+
3
3
  class FieldSpec
4
-
4
+
5
5
  class UnknownSqlTypeError < RuntimeError; end
6
-
6
+
7
7
  def initialize(model, name, type, options={})
8
8
  raise ArgumentError, "you cannot provide a field spec for the primary key" if name == model.primary_key
9
9
  self.model = model
@@ -12,40 +12,40 @@ module HoboFields
12
12
  self.options = options
13
13
  self.position = model.field_specs.length
14
14
  end
15
-
15
+
16
16
  attr_accessor :model, :name, :type, :position, :options
17
-
17
+
18
18
  def sql_type
19
19
  options[:sql_type] or begin
20
20
  if native_type?(type)
21
21
  type
22
22
  else
23
23
  field_class = HoboFields.to_class(type)
24
- field_class && field_class::COLUMN_TYPE or raise UnknownSqlTypeError, "#{model}.#{name}::#{type}"
24
+ field_class && field_class::COLUMN_TYPE or raise UnknownSqlTypeError, "#{type.inspect} for #{model}.#{name}"
25
25
  end
26
26
  end
27
27
  end
28
-
28
+
29
29
  def limit
30
30
  options[:limit] || native_types[sql_type][:limit]
31
31
  end
32
-
32
+
33
33
  def precision
34
34
  options[:precision]
35
35
  end
36
-
36
+
37
37
  def scale
38
38
  options[:scale]
39
39
  end
40
-
40
+
41
41
  def null
42
42
  :null.in?(options) ? options[:null] : true
43
43
  end
44
-
44
+
45
45
  def default
46
46
  options[:default]
47
47
  end
48
-
48
+
49
49
  def different_to?(col_spec)
50
50
  sql_type != col_spec.type ||
51
51
  begin
@@ -55,18 +55,18 @@ module HoboFields
55
55
  check_cols.any? { |k| col_spec.send(k) != self.send(k) }
56
56
  end
57
57
  end
58
-
59
-
58
+
59
+
60
60
  private
61
-
61
+
62
62
  def native_type?(type)
63
63
  type.in?(native_types.keys - [:primary_key])
64
64
  end
65
-
65
+
66
66
  def native_types
67
- model.connection.native_database_types
67
+ MigrationGenerator.native_types
68
68
  end
69
-
69
+
70
70
  end
71
-
71
+
72
72
  end
@@ -1,12 +1,12 @@
1
1
  module HoboFields
2
-
3
- FieldsDeclaration = classy_module do
4
-
2
+
3
+ FieldsDeclaration = classy_module do
4
+
5
5
  def self.fields(&b)
6
6
  # Any model that calls 'fields' gets a bunch of other
7
7
  # functionality included automatically, but make sure we only include it once
8
8
  include HoboFields::ModelExtensions unless HoboFields::ModelExtensions.in?(included_modules)
9
-
9
+
10
10
  if b
11
11
  dsl = FieldDeclarationDsl.new(self)
12
12
  if b.arity == 1
@@ -16,7 +16,7 @@ module HoboFields
16
16
  end
17
17
  end
18
18
  end
19
-
19
+
20
20
  end
21
21
 
22
22
  end
@@ -1,10 +1,8 @@
1
1
  module HoboFields
2
-
3
- class HtmlString < String
4
-
5
- COLUMN_TYPE = :text
6
-
7
- def to_html
2
+
3
+ class HtmlString < HoboFields::Text
4
+
5
+ def to_html(xmldoctype = true)
8
6
  self
9
7
  end
10
8
 
@@ -1,10 +1,10 @@
1
1
  module HoboFields
2
-
2
+
3
3
  class MarkdownString < HoboFields::Text
4
-
4
+
5
5
  HoboFields.register_type(:markdown, self)
6
6
 
7
- def to_html
7
+ def to_html(xmldoctype = true)
8
8
  blank? ? "" : BlueCloth.new(self).to_html
9
9
  end
10
10