cacheable_delegator 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGMxYmRiOTU2OTM4YmU0YTJkMzJmYTMxODNlMWUyYmM4YmQ5YTJhMw==
4
+ Y2E2MWQyMTY5NWZiZmU0YjJiYTMxYTY5ZWNlZTZjMmMxYzk1OGU1MA==
5
5
  data.tar.gz: !binary |-
6
- NDFjZjQxZjM5ZTA4YTZjOWFlY2ZiMDViMGYwYWEzZWJmNWExNmNhOQ==
6
+ NTgyMTVkZGY4NTI2ZGIxMzUwY2QyYzYzMGIwODJkMzYyYTAyNjJhOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGY0YzI5MDU3OGI5Yjk5ZjExNDZhNThiMmE1NmE2Yjk4MzMwMmMzODgxODk5
10
- OTRhYTEwMmRiOGJiMmNiODQ4MzFjNjI2MDc5NjBkMThkNmYyOWFkY2YwNWJj
11
- MGQxYjYxMDYzODYwMWQwNTQ3NGUwNDJmNjA2OTU0MzQyZTUzMTM=
9
+ Njk5MDI5MGU4ZmRkNzc3ZTJiZjYzZDhmNzJmZDg4MGQzNjE2Yzk4MzkxMjM5
10
+ OWI3MzY2NmViZGFkMmFhMGE3NDZhMjVlYzJiYTUyZmNmNjAzM2I5OWM0ODAw
11
+ Mjg2ZDgyNGI2NDMwY2E3MTA2NDY2OTg3N2QzYmE0ZmUxN2EwZTY=
12
12
  data.tar.gz: !binary |-
13
- OTU2M2Q4M2FiOTRlN2MyYTNhZGJmMzBlYzdkNzVjNDdlYjRhNDI1NmI2NTBk
14
- OWY0MDdiYjFkMDQ3NGYwNzIyNzUzOWU4MDZkY2VjMzRjYTUwNzZiMmIwYWRh
15
- NmJiMWJhNzY1Yzc5MjY3ZGUzNjZjNjA4NjBlMThkOGY1M2MxODE=
13
+ MDg1M2E0ZTQxM2YxNTY4MmJlZWIyYzhkNTE5OTQ1OTExMGUyMTIxOTVkNmJk
14
+ ZmI4OWNkOTIwM2U0M2ViMzQwMTFlNWQ2Yzc1YjY1MzZlMTQ3MDc1OWQ1NTQ3
15
+ NjNmNzYwYjgyZWVkYzgxMDVhYWViMjBkZjg0YzZhYWYzN2UyYzk=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cacheable_delegator"
8
- s.version = "1.3.0"
8
+ s.version = "1.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Nguyen"]
12
- s.date = "2013-10-29"
12
+ s.date = "2013-10-30"
13
13
  s.description = "Create a cache model for your active records"
14
14
  s.email = "dansonguyen@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -51,35 +51,49 @@ module CacheableDelegator
51
51
  # will call ActiveRecord::Base.serialize based on parameters passed in
52
52
  # from
53
53
  def upgrade_schema!
54
- # first we create a hash of source_columns
55
- source_column_hash = source_columns.inject({}) do |shash, source_col|
56
- source_col_atts = COL_ATTRIBUTES_TO_UPGRADE.inject({}){|hsh, att| hsh[att.to_sym] = source_col.send att; hsh }
57
- shash[source_col.name] = source_col_atts
58
-
59
- shash
60
- end
61
-
62
54
  # then we merge it with custom_columns
63
- columns_to_add = source_column_hash.merge(custom_columns)
64
-
55
+ columns_to_add = generate_columns_to_upgrade(custom_columns)
65
56
 
66
57
  # then we add them all in using .col method from active_record_inline_schema
67
58
  columns_to_add.each_pair do |col_name, col_atts|
68
- is_serialize = col_atts.delete(:serialize)
69
- col col_name, col_atts
59
+ column_atts_without_serialized_att = col_atts.dup.tap{|h| h.delete :serialize }
60
+ col( col_name, column_atts_without_serialized_att )
61
+ end
62
+
63
+ self.auto_upgrade!( :gentle => true )
64
+ self.set_serialized_columns!
65
+ end
70
66
 
71
- # by default, the client passes in serialize: true for plain serialization
72
- # and has the option to pass in serialize: Hash
73
- if is_serialize
67
+
68
+ # a soft method that is run every time the class is loaded
69
+ # just to make sure things are properly serialized
70
+ def set_serialized_columns!
71
+ cols = generate_columns_to_upgrade(custom_columns)
72
+ cols.each_pair do |col_name, col_atts|
73
+ if is_serialize = col_atts.delete(:serialize)
74
+ ## by default, the client passes in serialize: true for plain serialization
75
+ ## and has the option to pass in serialize: Hash
76
+
74
77
  serialize_klass = (is_serialize == true) ? Object : is_serialize
75
78
  serialize col_name, serialize_klass
76
79
  end
77
80
  end
78
-
79
- self.auto_upgrade!( :gentle => true )
80
81
  end
81
82
 
82
83
 
84
+ def generate_columns_to_upgrade(custom_cols)
85
+ # first we create a hash of source_columns
86
+ source_column_hash = source_columns.inject({}){ |shash, source_col|
87
+ source_col_atts = COL_ATTRIBUTES_TO_UPGRADE.inject({}){|hsh, att| hsh[att.to_sym] = source_col.send att; hsh }
88
+ shash[source_col.name] = source_col_atts
89
+
90
+ shash
91
+ }
92
+
93
+ # then we merge it with custom_columns
94
+ return source_column_hash.merge(custom_cols)
95
+ end
96
+
83
97
  ##################### source conveniences
84
98
 
85
99
 
@@ -77,6 +77,9 @@ describe CacheableDelegator do
77
77
  MyCachedRecord.add_custom_column :foo_array, serialize: Hash
78
78
  MyCachedRecord.upgrade_schema!
79
79
  expect{ MyCachedRecord.create_cache(@source) }.to raise_error ActiveRecord::SerializationTypeMismatch
80
+
81
+ # throwing this in there ad hoc to make sure nothing breaks...TODO fix later
82
+ MyCachedRecord.set_serialized_columns!
80
83
  end
81
84
 
82
85
  end
data/spec/spec_records.rb CHANGED
@@ -91,6 +91,8 @@ class MyCachedRecord < ActiveRecord::Base
91
91
 
92
92
  include CacheableDelegator
93
93
  cache_and_delegate MyRecord
94
+
95
+ self.set_serialized_columns!
94
96
  end
95
97
  MyCachedRecord.reset_column_information
96
98
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cacheable_delegator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-29 00:00:00.000000000 Z
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry