hobo_fields 2.0.1 → 2.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 260c0dbe5e12d3b92f760ee5868fb0fb69645415
4
+ data.tar.gz: 14ca25b167b77d6b96e528d8ab23ed52ceaf0d36
5
+ SHA512:
6
+ metadata.gz: 072e9859d3fc1024b5bf0af545cf8179b461b0ab4350ba875a88b32f51ec4be31dd6a57c0d4b2f508111b81687e54bbd2c0b0dab57e37a8fdb62632d48240dac
7
+ data.tar.gz: 5f26cda68869c92d3644e63e218278228cd4733807147210552f930b163c74abeadef05d67bca4f1c948ddd173229e3070a4a1dfc361775f6729e1cc5cff3679
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'rubydoctest', :git => 'git://github.com/bryanlarsen/rubydoctest.git'
4
- gem 'rails', '3.2.12'
4
+ gem 'rails'
5
5
  gem 'yard'
6
+ gem 'protected_attributes'
7
+
6
8
  gemspec :path => "../hobo_support"
7
9
  gemspec
8
10
  platform :ruby do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.0.pre1
@@ -1,4 +1,21 @@
1
1
  ActiveRecord::Base.class_eval do
2
+ def read_attribute_with_hobo(attr_name)
3
+ name = attr_name.to_s
4
+ if self.class.can_wrap_with_hobo_type?(name)
5
+ attr_name = attr_name.to_sym
6
+ val = read_attribute_without_hobo(name)
7
+ wrapper_type = self.class.attr_type(attr_name)
8
+ if HoboFields.can_wrap?(wrapper_type, val)
9
+ wrapper_type.new(val)
10
+ else
11
+ val
12
+ end
13
+ else
14
+ read_attribute_without_hobo(name)
15
+ end
16
+ end
17
+ alias_method_chain :read_attribute, :hobo
18
+
2
19
  class << self
3
20
 
4
21
  def can_wrap_with_hobo_type?(attr_name)
@@ -10,52 +27,6 @@ ActiveRecord::Base.class_eval do
10
27
  end
11
28
  end
12
29
 
13
- # Rails 3.2+
14
- def internal_attribute_access_code(attr_name, cast_code)
15
- access_code = "(v=@attributes[attr_name]) && #{cast_code}"
16
-
17
- unless attr_name == primary_key
18
- access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ")
19
- end
20
-
21
- # This is the Hobo hook - add a type wrapper around the field
22
- # value if we have a special type defined
23
- if can_wrap_with_hobo_type?(attr_name)
24
- access_code = "val = begin; #{access_code}; end; wrapper_type = self.class.attr_type(:#{attr_name}); " +
25
- "if HoboFields.can_wrap?(wrapper_type, val); wrapper_type.new(val); else; val; end"
26
- end
27
-
28
- if cache_attribute?(attr_name)
29
- access_code = "@attributes_cache['#{attr_name}'] ||= begin; #{access_code}; end;"
30
- end
31
-
32
- "attr_name = '#{attr_name}'; #{access_code}"
33
- end
34
-
35
- # Rails 3.1 or earlier
36
- # Define an attribute reader method. Cope with nil column.
37
- def define_read_method(symbol, attr_name, column)
38
- cast_code = column.type_cast_code('v') if column
39
- access_code = cast_code ? "(v=@attributes['#{attr_name}']) && #{cast_code}" : "@attributes['#{attr_name}']"
40
-
41
- unless attr_name.to_s == self.primary_key.to_s
42
- access_code = access_code.insert(0, "missing_attribute('#{attr_name}', caller) unless @attributes.has_key?('#{attr_name}'); ")
43
- end
44
-
45
- # This is the Hobo hook - add a type wrapper around the field
46
- # value if we have a special type defined
47
- if can_wrap_with_hobo_type?(symbol)
48
- access_code = "val = begin; #{access_code}; end; wrapper_type = self.class.attr_type(:#{attr_name}); " +
49
- "if HoboFields.can_wrap?(wrapper_type, val); wrapper_type.new(val); else; val; end"
50
- end
51
-
52
- if cache_attribute?(attr_name)
53
- access_code = "@attributes_cache['#{attr_name}'] ||= begin; #{access_code}; end;"
54
- end
55
-
56
- generated_attribute_methods.module_eval("def #{symbol}; #{access_code}; end", __FILE__, __LINE__)
57
- end
58
-
59
30
  def define_method_attribute=(attr_name)
60
31
  if can_wrap_with_hobo_type?(attr_name)
61
32
  src = "begin; wrapper_type = self.class.attr_type(:#{attr_name}); " +
@@ -13,7 +13,7 @@ module HoboFields
13
13
  Kramdown::Document
14
14
  when defined?(Maruku)
15
15
  Maruku
16
- else
16
+ when defined?(Markdown)
17
17
  Markdown
18
18
  end
19
19
 
@@ -9,7 +9,7 @@ module HoboFields
9
9
  Kramdown::Document
10
10
  when defined?(Maruku)
11
11
  Maruku
12
- else
12
+ when defined?(Markdown)
13
13
  Markdown
14
14
  end
15
15
 
@@ -3,7 +3,7 @@ module HoboFields
3
3
  module Types
4
4
  class Text < String
5
5
 
6
- COLUMN_TYPE = :text
6
+ COLUMN_TYPE = :text unless defined? COLUMN_TYPE
7
7
 
8
8
  def to_html(xmldoctype = true)
9
9
  ERB::Util.html_escape(self).gsub("\n", "<br#{xmldoctype ? ' /' : ''}>\n").html_safe
@@ -1,5 +1,3 @@
1
- require 'redcloth'
2
-
3
1
  module HoboFields
4
2
  module Types
5
3
  class TextileString < HoboFields::Types::Text
@@ -7,6 +5,8 @@ module HoboFields
7
5
  include SanitizeHtml
8
6
 
9
7
  def to_html(xmldoctype = true)
8
+ require 'redcloth'
9
+
10
10
  if blank?
11
11
  ""
12
12
  else
data/lib/hobo_fields.rb CHANGED
@@ -92,6 +92,26 @@ module HoboFields
92
92
 
93
93
  end
94
94
 
95
- require 'hobo_fields/railtie'
95
+ require 'hobo_fields/extensions/active_record/attribute_methods'
96
+ require 'hobo_fields/extensions/active_record/fields_declaration'
97
+ require 'hobo_fields/field_declaration_dsl'
98
+ require 'hobo_fields/model'
99
+ require 'hobo_fields/sanitize_html'
100
+ require 'hobo_fields/model/field_spec'
101
+ require 'hobo_fields/model/index_spec'
102
+ require 'hobo_fields/types/email_address'
103
+ require 'hobo_fields/types/enum_string'
104
+ require 'hobo_fields/types/html_string'
105
+ require 'hobo_fields/types/lifecycle_state'
106
+ require 'hobo_fields/types/password_string'
107
+ require 'hobo_fields/types/raw_html_string'
108
+ # Disabled to avoid errors with Rails 4 and Ruby 2.0, they will be loaded later
109
+ # require 'hobo_fields/types/markdown_string'
110
+ # require 'hobo_fields/types/raw_markdown_string'
111
+ require 'hobo_fields/types/serialized_object'
112
+ require 'hobo_fields/types/text'
113
+ require 'hobo_fields/types/textile_string'
114
+
115
+ require 'hobo_fields/railtie' if defined?(Rails)
96
116
 
97
117
 
@@ -23,11 +23,11 @@ doctest: module content matches
23
23
 
24
24
 
25
25
  doctest: test file exists
26
- >> File.exist? 'test/unit/alpha/beta_test.rb'
26
+ >> File.exist? 'test/models/alpha/beta_test.rb'
27
27
  => true
28
28
 
29
29
  doctest: test content matches
30
- >> File.read 'test/unit/alpha/beta_test.rb'
30
+ >> File.read 'test/models/alpha/beta_test.rb'
31
31
  =>
32
32
  require 'test_helper'
33
33
 
@@ -19,7 +19,7 @@ And requires also that you enter the right choice when prompted. OK we're ready
19
19
  class Foo < ActiveRecord::Base
20
20
  fields do
21
21
  end
22
- set_primary_key "foo_id"
22
+ self.primary_key="foo_id"
23
23
  end
24
24
  >> Rails::Generators.invoke 'hobo:migration', %w(-n -m)
25
25
  >> Foo.primary_key
@@ -29,7 +29,7 @@ And requires also that you enter the right choice when prompted. OK we're ready
29
29
  doctest: rename from custom primary_key
30
30
  >>
31
31
  class Foo < ActiveRecord::Base
32
- set_primary_key "id"
32
+ self.primary_key="id"
33
33
  end
34
34
  puts "\n\e[45m Please enter 'id' (no quotes) at the next prompt \e[0m"
35
35
  >> Rails::Generators.invoke 'hobo:migration', %w(-n -m)
@@ -41,7 +41,7 @@ And requires also that you enter the right choice when prompted. OK we're ready
41
41
  doctest: rename to custom primary_key
42
42
  >>
43
43
  class Foo < ActiveRecord::Base
44
- set_primary_key "foo_id"
44
+ self.primary_key="foo_id"
45
45
  end
46
46
  puts "\n\e[45m Please enter 'drop id' (no quotes) at the next prompt \e[0m"
47
47
  >> Rails::Generators.invoke 'hobo:migration', %w(-n -m)
@@ -445,7 +445,7 @@ The migration generator respects the `set_table_name` declaration, although as b
445
445
 
446
446
  >>
447
447
  class Advert
448
- set_table_name "ads"
448
+ self.table_name="ads"
449
449
  fields do
450
450
  title :string, :default => "Untitled"
451
451
  body :text
@@ -459,7 +459,7 @@ The migration generator respects the `set_table_name` declaration, although as b
459
459
 
460
460
  Set the table name back to what it should be and confirm we're in sync:
461
461
 
462
- >> class Advert; set_table_name "adverts"; end
462
+ >> class Advert; self.table_name="adverts"; end
463
463
  >> Generators::Hobo::Migration::Migrator.run
464
464
  => ["", ""]
465
465
 
@@ -626,7 +626,7 @@ HoboFields has some support for legacy keys.
626
626
  name :string, :default => "No Name"
627
627
  body :text
628
628
  end
629
- set_primary_key "advert_id"
629
+ self.primary_key="advert_id"
630
630
  end
631
631
  >> up, down = Generators::Hobo::Migration::Migrator.run(:adverts => {:id => :advert_id})
632
632
  >> up
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobo_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
5
- prerelease:
4
+ version: 2.1.0.pre1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tom Locke
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-23 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: hobo_support
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: 2.0.1
19
+ version: 2.1.0.pre1
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: 2.0.1
26
+ version: 2.1.0.pre1
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rubydoctest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: RedCloth
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: kramdown
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - '>='
76
67
  - !ruby/object:Gem::Version
@@ -128,28 +119,26 @@ files:
128
119
  - test_responses.txt
129
120
  homepage: http://hobocentral.net
130
121
  licenses: []
122
+ metadata: {}
131
123
  post_install_message:
132
124
  rdoc_options:
133
125
  - --charset=UTF-8
134
126
  require_paths:
135
127
  - lib
136
128
  required_ruby_version: !ruby/object:Gem::Requirement
137
- none: false
138
129
  requirements:
139
130
  - - '>='
140
131
  - !ruby/object:Gem::Version
141
132
  version: '0'
142
133
  required_rubygems_version: !ruby/object:Gem::Requirement
143
- none: false
144
134
  requirements:
145
135
  - - '>='
146
136
  - !ruby/object:Gem::Version
147
137
  version: 1.3.6
148
138
  requirements: []
149
139
  rubyforge_project: hobo
150
- rubygems_version: 1.8.25
140
+ rubygems_version: 2.1.11
151
141
  signing_key:
152
- specification_version: 3
142
+ specification_version: 4
153
143
  summary: Rich field types and migration generator for Rails
154
144
  test_files: []
155
- has_rdoc: