has_custom_fields 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_custom_fields}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{kylejginavan}]
12
- s.date = %q{2011-09-05}
11
+ s.authors = ["kylejginavan"]
12
+ s.date = %q{2011-12-02}
13
13
  s.description = %q{Uses a vertical schema to add custom fields.}
14
14
  s.email = %q{kylejginavan@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -46,20 +46,9 @@ Gem::Specification.new do |s|
46
46
  "spec/spec_helper.rb"
47
47
  ]
48
48
  s.homepage = %q{http://github.com/kylejginavan/has_custom_fields}
49
- s.require_paths = [%q{lib}]
50
- s.rubygems_version = %q{1.8.8}
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.5.2}
51
51
  s.summary = %q{The easy way to add custom fields to any Rails model.}
52
- s.test_files = [
53
- "spec/fixtures/document.rb",
54
- "spec/fixtures/person.rb",
55
- "spec/fixtures/post.rb",
56
- "spec/fixtures/preference.rb",
57
- "spec/models/eav_model_with_no_arguments_spec.rb",
58
- "spec/models/eav_model_with_options_spec.rb",
59
- "spec/models/eav_validation_spec.rb",
60
- "spec/schema.rb",
61
- "spec/spec_helper.rb"
62
- ]
63
52
 
64
53
  if s.respond_to? :specification_version then
65
54
  s.specification_version = 3
@@ -2,6 +2,8 @@
2
2
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
3
  <plist version="1.0">
4
4
  <dict>
5
+ <key>currentDocument</key>
6
+ <string>lib/has_custom_fields.rb</string>
5
7
  <key>documents</key>
6
8
  <array>
7
9
  <dict>
@@ -18,10 +20,44 @@
18
20
  <key>fileHierarchyDrawerWidth</key>
19
21
  <integer>200</integer>
20
22
  <key>metaData</key>
21
- <dict/>
23
+ <dict>
24
+ <key>lib/custom_fields/custom_field_base.rb</key>
25
+ <dict>
26
+ <key>caret</key>
27
+ <dict>
28
+ <key>column</key>
29
+ <integer>0</integer>
30
+ <key>line</key>
31
+ <integer>9</integer>
32
+ </dict>
33
+ <key>firstVisibleColumn</key>
34
+ <integer>0</integer>
35
+ <key>firstVisibleLine</key>
36
+ <integer>0</integer>
37
+ </dict>
38
+ <key>lib/has_custom_fields.rb</key>
39
+ <dict>
40
+ <key>caret</key>
41
+ <dict>
42
+ <key>column</key>
43
+ <integer>20</integer>
44
+ <key>line</key>
45
+ <integer>56</integer>
46
+ </dict>
47
+ <key>firstVisibleColumn</key>
48
+ <integer>0</integer>
49
+ <key>firstVisibleLine</key>
50
+ <integer>49</integer>
51
+ </dict>
52
+ </dict>
53
+ <key>openDocuments</key>
54
+ <array>
55
+ <string>lib/custom_fields/custom_field_base.rb</string>
56
+ <string>lib/has_custom_fields.rb</string>
57
+ </array>
22
58
  <key>showFileHierarchyDrawer</key>
23
59
  <true/>
24
60
  <key>windowFrame</key>
25
- <string>{{2128, 135}, {1203, 1047}}</string>
61
+ <string>{{465, 4}, {1203, 1024}}</string>
26
62
  </dict>
27
63
  </plist>
@@ -15,14 +15,15 @@ module CustomFields
15
15
  validates_inclusion_of :style, :in => ALLOWABLE_TYPES, :message => "Invalid style. Should be #{ALLOWABLE_TYPES.join(', ')}."
16
16
  FOO
17
17
  end
18
-
18
+
19
19
  def select_options_data
20
20
  (self.select_options || []).join(",")
21
21
  end
22
22
 
23
- def select_options_data=(csv)
24
- self.select_options = csv.split(",").collect{|f| f.strip}
23
+ def select_options_data=(data)
24
+ self.select_options = data.split(",").collect{|f| f.strip}
25
25
  end
26
26
 
27
+ #scope :find_all_by_scope, lambda {|scope| {where("#{scope}_id = #{self.id}")}}
27
28
  end
28
29
  end
@@ -10,7 +10,7 @@ module ActiveRecord # :nodoc:
10
10
  #
11
11
  module CustomFields
12
12
 
13
- ALLOWABLE_TYPES = ['select', 'boolean', 'text', 'date']
13
+ ALLOWABLE_TYPES = ['select', 'checkbox', 'text', 'date']
14
14
 
15
15
  Object.const_set('TagFacade', Class.new(Object)).class_eval do
16
16
  def initialize(object_with_custom_fields, scope, scope_id)
@@ -86,7 +86,7 @@ module ActiveRecord # :nodoc:
86
86
  # Provide default options
87
87
  options[:fields_class_name] ||= self.name + 'Field'
88
88
  options[:fields_table_name] ||= options[:fields_class_name].tableize
89
- options[:fields_relationship_name] ||= options[:fields_class_name].tableize.to_sym
89
+ options[:fields_relationship_name] ||= options[:fields_class_name].underscore.to_sym
90
90
 
91
91
  options[:values_class_name] ||= self.name + 'Attribute'
92
92
  options[:values_table_name] ||= options[:values_class_name].tableize
@@ -229,7 +229,8 @@ module ActiveRecord # :nodoc:
229
229
  end
230
230
  t.timestamps
231
231
  end
232
- self.connection.add_index options[:fields_table_name], scope_fkeys + [options[:name_field]], :unique => true
232
+ self.connection.add_index options[:fields_table_name], scope_fkeys + [options[:name_field]], :unique => true,
233
+ :name => "#{options[:fields_table_name]}_unique_index"
233
234
 
234
235
  # add foreign keys for scoping tables
235
236
  options[:scopes].each do |s|
@@ -251,17 +252,17 @@ module ActiveRecord # :nodoc:
251
252
 
252
253
  self.connection.create_table(options[:values_table_name], options) do |t|
253
254
  t.integer options[:foreign_key], :null => false
254
- t.integer options[:fields_table_name].foreign_key, :null => false
255
+ t.integer options[:fields_table_name].singularize.foreign_key, :null => false
255
256
  t.string options[:value_field], :null => false
256
257
  t.timestamps
257
258
  end
258
259
 
259
260
  self.connection.add_index options[:values_table_name], options[:foreign_key]
260
- self.connection.add_index options[:values_table_name], options[:fields_table_name].foreign_key
261
+ self.connection.add_index options[:values_table_name], options[:fields_table_name].singularize.foreign_key
261
262
 
262
263
  self.connection.execute <<-FOO
263
264
  alter table #{options[:values_table_name]}
264
- add foreign key (#{options[:fields_table_name].foreign_key})
265
+ add foreign key (#{options[:fields_table_name].singularize.foreign_key})
265
266
  references #{options[:fields_table_name]}(#{eval(options[:fields_class_name]).primary_key})
266
267
  FOO
267
268
  end
@@ -326,11 +327,11 @@ module ActiveRecord # :nodoc:
326
327
  def get_value_object(attribute_name, scope, scope_id)
327
328
  ::Rails.logger.debug("scope/id is: #{scope}/#{scope_id}")
328
329
  options = custom_field_options[self.class.name]
329
- model_fkey = options[:foreign_key]
330
+ model_fkey = options[:foreign_key].singularize
330
331
  fields_class = options[:fields_class_name]
331
332
  values_class = options[:values_class_name]
332
333
  value_field = options[:value_field]
333
- fields_fkey = options[:fields_table_name].foreign_key
334
+ fields_fkey = options[:fields_table_name].singularize.foreign_key
334
335
  fields = Object.const_get(fields_class)
335
336
  values = Object.const_get(values_class)
336
337
  ::Rails.logger.debug("fkey is: #{fields_fkey}")
@@ -347,7 +348,6 @@ module ActiveRecord # :nodoc:
347
348
  value_object = values.new model_fkey => self.id,
348
349
  fields_fkey => f.id
349
350
  end
350
-
351
351
  return value_object
352
352
  end
353
353
 
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_custom_fields
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease:
5
- version: 0.0.3
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
6
11
  platform: ruby
7
12
  authors:
8
13
  - kylejginavan
@@ -10,7 +15,8 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-09-05 00:00:00 Z
18
+ date: 2011-12-02 00:00:00 -06:00
19
+ default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: builder
@@ -20,6 +26,9 @@ dependencies:
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
23
32
  version: "0"
24
33
  type: :runtime
25
34
  version_requirements: *id001
@@ -60,6 +69,7 @@ files:
60
69
  - spec/schema.rb
61
70
  - spec/spec.opts
62
71
  - spec/spec_helper.rb
72
+ has_rdoc: true
63
73
  homepage: http://github.com/kylejginavan/has_custom_fields
64
74
  licenses: []
65
75
 
@@ -73,27 +83,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
83
  requirements:
74
84
  - - ">="
75
85
  - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
76
89
  version: "0"
77
90
  required_rubygems_version: !ruby/object:Gem::Requirement
78
91
  none: false
79
92
  requirements:
80
93
  - - ">="
81
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
82
98
  version: "0"
83
99
  requirements: []
84
100
 
85
101
  rubyforge_project:
86
- rubygems_version: 1.8.8
102
+ rubygems_version: 1.5.2
87
103
  signing_key:
88
104
  specification_version: 3
89
105
  summary: The easy way to add custom fields to any Rails model.
90
- test_files:
91
- - spec/fixtures/document.rb
92
- - spec/fixtures/person.rb
93
- - spec/fixtures/post.rb
94
- - spec/fixtures/preference.rb
95
- - spec/models/eav_model_with_no_arguments_spec.rb
96
- - spec/models/eav_model_with_options_spec.rb
97
- - spec/models/eav_validation_spec.rb
98
- - spec/schema.rb
99
- - spec/spec_helper.rb
106
+ test_files: []
107
+