datts_right 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datts_right (0.0.10)
4
+ datts_right (0.0.11)
5
5
  datts_right
6
6
  rails (>= 3.0.0)
7
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
data/datts_right.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datts_right}
8
- s.version = "0.0.11"
8
+ s.version = "0.0.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ramon Tayag"]
@@ -188,6 +188,18 @@ Gem::Specification.new do |s|
188
188
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
189
189
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
190
190
  s.add_development_dependency(%q<rcov>, [">= 0"])
191
+ s.add_development_dependency(%q<autotest>, [">= 0"])
192
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
193
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
194
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
195
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
196
+ s.add_development_dependency(%q<rcov>, [">= 0"])
197
+ s.add_development_dependency(%q<autotest>, [">= 0"])
198
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
199
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
200
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
201
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
202
+ s.add_development_dependency(%q<rcov>, [">= 0"])
191
203
  else
192
204
  s.add_dependency(%q<datts_right>, [">= 0"])
193
205
  s.add_dependency(%q<rails>, [">= 3.0.0"])
@@ -324,6 +336,18 @@ Gem::Specification.new do |s|
324
336
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
325
337
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
326
338
  s.add_dependency(%q<rcov>, [">= 0"])
339
+ s.add_dependency(%q<autotest>, [">= 0"])
340
+ s.add_dependency(%q<sqlite3>, [">= 0"])
341
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
342
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
343
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
344
+ s.add_dependency(%q<rcov>, [">= 0"])
345
+ s.add_dependency(%q<autotest>, [">= 0"])
346
+ s.add_dependency(%q<sqlite3>, [">= 0"])
347
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
348
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
349
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
350
+ s.add_dependency(%q<rcov>, [">= 0"])
327
351
  end
328
352
  else
329
353
  s.add_dependency(%q<datts_right>, [">= 0"])
@@ -461,6 +485,18 @@ Gem::Specification.new do |s|
461
485
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
462
486
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
463
487
  s.add_dependency(%q<rcov>, [">= 0"])
488
+ s.add_dependency(%q<autotest>, [">= 0"])
489
+ s.add_dependency(%q<sqlite3>, [">= 0"])
490
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
491
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
492
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
493
+ s.add_dependency(%q<rcov>, [">= 0"])
494
+ s.add_dependency(%q<autotest>, [">= 0"])
495
+ s.add_dependency(%q<sqlite3>, [">= 0"])
496
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
497
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
498
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
499
+ s.add_dependency(%q<rcov>, [">= 0"])
464
500
  end
465
501
  end
466
502
 
@@ -9,11 +9,12 @@ class DynamicAttribute < ActiveRecord::Base
9
9
 
10
10
  def value=(v)
11
11
  object_type = self.class.attr_type?(v)
12
-
13
- if self.object_type == object_type # has to be the same kind of object
14
- send "#{self.class.attr_column(v)}=", v
15
- elsif v.nil?
12
+ if v.nil?
16
13
  send "#{self.object_type}_value=", v
14
+ elsif object_type == "string" && self.object_type == "text"
15
+ self.text_value = v
16
+ else
17
+ send "#{self.class.attr_column(v)}=", v
17
18
  end
18
19
  end
19
20
 
@@ -12,11 +12,12 @@ module DattsRight
12
12
  end
13
13
 
14
14
  def remove_dynamic_attribute(name)
15
+ # Remove from the cache
16
+ @dynamic_attributes_cache.delete(name.to_sym)
17
+
18
+ # Then remove from the db
15
19
  dynamic_attribute = dynamic_attributes.find_by_attr_key(name.to_s)
16
- if dynamic_attribute
17
- @dynamic_attributes_cache.delete(name.to_sym)
18
- dynamic_attribute.destroy
19
- end
20
+ dynamic_attribute.destroy if dynamic_attribute
20
21
  end
21
22
 
22
23
  # Give users access to the cache
@@ -51,21 +52,21 @@ module DattsRight
51
52
 
52
53
  # Like AR::Base#read_attribute
53
54
  def read_dynamic_attribute(attr_name)
54
- attr_name = attr_name.to_s
55
+ attr_name = attr_name.to_sym
55
56
  if dynamic_attribute?(attr_name)
56
57
  #puts "Reading #{attr_name}. The whole cache: #{@dynamic_attributes_cache.inspect}"
57
- @dynamic_attributes_cache[attr_name.to_sym].value
58
+ @dynamic_attributes_cache[attr_name].value
58
59
  end
59
60
  end
60
61
 
61
62
  # Like AR::Base#write_attribute
62
63
  def write_dynamic_attribute(attr_name, value)
63
64
  #puts "attempting to write: #{attr_name} = #{value}"
65
+ attr_name = attr_name.to_sym
64
66
  if dynamic_attribute?(attr_name)
65
67
  #puts "#{attr_name} is a dynamic_attribute"
66
- attr_name = attr_name.to_s
67
68
  #puts "Writing @dynamic_attributes_cache[:#{attr_name}].value = #{value}"
68
- dynamic_attribute = @dynamic_attributes_cache[attr_name.to_sym]
69
+ dynamic_attribute = @dynamic_attributes_cache[attr_name]
69
70
  dynamic_attribute.value = value
70
71
  #puts "In write_dynamic_attribute. Full cache: #{@dynamic_attributes_cache.inspect}"
71
72
  return dynamic_attribute.value
@@ -103,6 +104,35 @@ module DattsRight
103
104
  @dynamic_attributes_cache
104
105
  end
105
106
 
107
+ def method_missing(method_id, *args, &body)
108
+ #begin
109
+ #method_missing_without_dynamic_attributes method_id, *args, &block
110
+ #rescue NoMethodError => e
111
+ #attr_name = method_id.to_s.sub(/\=$/, '')
112
+ #if is_dynamic_attribute?(attr_name)
113
+ #if method_id.to_s =~ /\=$/
114
+ #return write_attribute_with_dynamic_attributes(attr_name, args[0])
115
+ #else
116
+ #return read_attribute_with_dynamic_attributes(attr_name)
117
+ #end
118
+ #end
119
+ #raise e
120
+ #end
121
+ begin
122
+ super(method_id, *args, &body)
123
+ rescue NoMethodError => e
124
+ attr_name = method_id.to_s.sub(/\=$/, '')
125
+ if dynamic_attribute?(attr_name)
126
+ #puts "#{attr_name} is a dynamic_attribute"
127
+ method_id.to_s =~ /\=$/ ? write_dynamic_attribute(attr_name, args[0]) : read_dynamic_attribute(attr_name)
128
+ #else
129
+ #super(method_id, *args, &body) # send it to super again, so that any magic activerecord needs to do will still work
130
+ else
131
+ raise NoMethodError
132
+ end
133
+ end
134
+ end
135
+
106
136
  alias :add_datt :add_dynamic_attribute
107
137
  alias :remove_datt :remove_dynamic_attribute
108
138
  alias :read_datt :read_dynamic_attribute
@@ -414,4 +414,25 @@ describe DattsRight do
414
414
  @page.dynamic_attribute_details(:body).value.should == @page.read_datt(:body)
415
415
  end
416
416
  end
417
+
418
+ it "should be able to write short strings into text variables" do
419
+ @page.add_datt(:body, "text")
420
+ @page.write_datt(:body, "short")
421
+ @page.save
422
+ @page.read_datt(:body).should == "short"
423
+ end
424
+
425
+ it "should write like a normal attribute" do
426
+ @page.add_datt(:body, "text")
427
+ @page.body = "dude"
428
+ @page.save
429
+ @page.read_datt(:body).should == "dude"
430
+ end
431
+
432
+ it "should read like a normal attribute" do
433
+ @page.add_datt(:body, "text")
434
+ @page.body = "dude"
435
+ @page.save
436
+ @page.body.should == "dude"
437
+ end
417
438
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datts_right
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramon Tayag
@@ -2044,6 +2044,186 @@ dependencies:
2044
2044
  name: rcov
2045
2045
  version_requirements: *id135
2046
2046
  prerelease: false
2047
+ - !ruby/object:Gem::Dependency
2048
+ type: :development
2049
+ requirement: &id136 !ruby/object:Gem::Requirement
2050
+ none: false
2051
+ requirements:
2052
+ - - ">="
2053
+ - !ruby/object:Gem::Version
2054
+ hash: 3
2055
+ segments:
2056
+ - 0
2057
+ version: "0"
2058
+ name: autotest
2059
+ version_requirements: *id136
2060
+ prerelease: false
2061
+ - !ruby/object:Gem::Dependency
2062
+ type: :development
2063
+ requirement: &id137 !ruby/object:Gem::Requirement
2064
+ none: false
2065
+ requirements:
2066
+ - - ">="
2067
+ - !ruby/object:Gem::Version
2068
+ hash: 3
2069
+ segments:
2070
+ - 0
2071
+ version: "0"
2072
+ name: sqlite3
2073
+ version_requirements: *id137
2074
+ prerelease: false
2075
+ - !ruby/object:Gem::Dependency
2076
+ type: :development
2077
+ requirement: &id138 !ruby/object:Gem::Requirement
2078
+ none: false
2079
+ requirements:
2080
+ - - ~>
2081
+ - !ruby/object:Gem::Version
2082
+ hash: 3
2083
+ segments:
2084
+ - 2
2085
+ - 3
2086
+ - 0
2087
+ version: 2.3.0
2088
+ name: rspec
2089
+ version_requirements: *id138
2090
+ prerelease: false
2091
+ - !ruby/object:Gem::Dependency
2092
+ type: :development
2093
+ requirement: &id139 !ruby/object:Gem::Requirement
2094
+ none: false
2095
+ requirements:
2096
+ - - ~>
2097
+ - !ruby/object:Gem::Version
2098
+ hash: 23
2099
+ segments:
2100
+ - 1
2101
+ - 0
2102
+ - 0
2103
+ version: 1.0.0
2104
+ name: bundler
2105
+ version_requirements: *id139
2106
+ prerelease: false
2107
+ - !ruby/object:Gem::Dependency
2108
+ type: :development
2109
+ requirement: &id140 !ruby/object:Gem::Requirement
2110
+ none: false
2111
+ requirements:
2112
+ - - ~>
2113
+ - !ruby/object:Gem::Version
2114
+ hash: 7
2115
+ segments:
2116
+ - 1
2117
+ - 5
2118
+ - 2
2119
+ version: 1.5.2
2120
+ name: jeweler
2121
+ version_requirements: *id140
2122
+ prerelease: false
2123
+ - !ruby/object:Gem::Dependency
2124
+ type: :development
2125
+ requirement: &id141 !ruby/object:Gem::Requirement
2126
+ none: false
2127
+ requirements:
2128
+ - - ">="
2129
+ - !ruby/object:Gem::Version
2130
+ hash: 3
2131
+ segments:
2132
+ - 0
2133
+ version: "0"
2134
+ name: rcov
2135
+ version_requirements: *id141
2136
+ prerelease: false
2137
+ - !ruby/object:Gem::Dependency
2138
+ type: :development
2139
+ requirement: &id142 !ruby/object:Gem::Requirement
2140
+ none: false
2141
+ requirements:
2142
+ - - ">="
2143
+ - !ruby/object:Gem::Version
2144
+ hash: 3
2145
+ segments:
2146
+ - 0
2147
+ version: "0"
2148
+ name: autotest
2149
+ version_requirements: *id142
2150
+ prerelease: false
2151
+ - !ruby/object:Gem::Dependency
2152
+ type: :development
2153
+ requirement: &id143 !ruby/object:Gem::Requirement
2154
+ none: false
2155
+ requirements:
2156
+ - - ">="
2157
+ - !ruby/object:Gem::Version
2158
+ hash: 3
2159
+ segments:
2160
+ - 0
2161
+ version: "0"
2162
+ name: sqlite3
2163
+ version_requirements: *id143
2164
+ prerelease: false
2165
+ - !ruby/object:Gem::Dependency
2166
+ type: :development
2167
+ requirement: &id144 !ruby/object:Gem::Requirement
2168
+ none: false
2169
+ requirements:
2170
+ - - ~>
2171
+ - !ruby/object:Gem::Version
2172
+ hash: 3
2173
+ segments:
2174
+ - 2
2175
+ - 3
2176
+ - 0
2177
+ version: 2.3.0
2178
+ name: rspec
2179
+ version_requirements: *id144
2180
+ prerelease: false
2181
+ - !ruby/object:Gem::Dependency
2182
+ type: :development
2183
+ requirement: &id145 !ruby/object:Gem::Requirement
2184
+ none: false
2185
+ requirements:
2186
+ - - ~>
2187
+ - !ruby/object:Gem::Version
2188
+ hash: 23
2189
+ segments:
2190
+ - 1
2191
+ - 0
2192
+ - 0
2193
+ version: 1.0.0
2194
+ name: bundler
2195
+ version_requirements: *id145
2196
+ prerelease: false
2197
+ - !ruby/object:Gem::Dependency
2198
+ type: :development
2199
+ requirement: &id146 !ruby/object:Gem::Requirement
2200
+ none: false
2201
+ requirements:
2202
+ - - ~>
2203
+ - !ruby/object:Gem::Version
2204
+ hash: 7
2205
+ segments:
2206
+ - 1
2207
+ - 5
2208
+ - 2
2209
+ version: 1.5.2
2210
+ name: jeweler
2211
+ version_requirements: *id146
2212
+ prerelease: false
2213
+ - !ruby/object:Gem::Dependency
2214
+ type: :development
2215
+ requirement: &id147 !ruby/object:Gem::Requirement
2216
+ none: false
2217
+ requirements:
2218
+ - - ">="
2219
+ - !ruby/object:Gem::Version
2220
+ hash: 3
2221
+ segments:
2222
+ - 0
2223
+ version: "0"
2224
+ name: rcov
2225
+ version_requirements: *id147
2226
+ prerelease: false
2047
2227
  description: Creates a separate table that saves all your dynamic attributes.
2048
2228
  email: ramon@tayag.net
2049
2229
  executables: []