bsm-models 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ module Bsm
8
8
  autoload :EagerDescendants, 'bsm/model/eager_descendants'
9
9
  autoload :StiConvertable, 'bsm/model/sti_convertable'
10
10
  autoload :HasManySerialized, 'bsm/model/has_many_serialized'
11
+ autoload :Coders, 'bsm/model/coders'
11
12
  end
12
13
 
13
14
  class Railtie < ::Rails::Railtie
@@ -0,0 +1,5 @@
1
+ module Bsm::Model::Coders
2
+ autoload :AbstractColumn, 'bsm/model/coders/abstract_column'
3
+ autoload :JsonColumn, 'bsm/model/coders/json_column'
4
+ autoload :MarshalColumn, 'bsm/model/coders/marshal_column'
5
+ end
@@ -0,0 +1,42 @@
1
+ class Bsm::Model::Coders::AbstractColumn
2
+
3
+ def self.rescue_errors
4
+ []
5
+ end
6
+
7
+ # @attr_reader [Class] object_class
8
+ attr_reader :object_class
9
+
10
+ # @param [Class] obejct_class
11
+ def initialize(object_class = Object)
12
+ @object_class = object_class
13
+ end
14
+
15
+ def dump(obj)
16
+ not_implemented
17
+ end
18
+
19
+ def load(string)
20
+ return object_class.new if object_class != Object && string.nil?
21
+ begin
22
+ obj = _load(string) unless string.nil?
23
+
24
+ unless obj.is_a?(object_class) || obj.nil?
25
+ raise ActiveRecord::SerializationTypeMismatch,
26
+ "Attribute was supposed to be a #{object_class}, but was a #{obj.class}"
27
+ end
28
+ obj ||= object_class.new if object_class != Object
29
+
30
+ obj
31
+ rescue *self.class.rescue_errors
32
+ object_class == Object ? string : object_class.new
33
+ end
34
+ end
35
+
36
+ protected
37
+
38
+ def _load(string)
39
+ not_implemented
40
+ end
41
+
42
+ end
@@ -0,0 +1,17 @@
1
+ class Bsm::Model::Coders::JsonColumn < Bsm::Model::Coders::AbstractColumn
2
+
3
+ def self.rescue_errors
4
+ [ MultiJson::DecodeError ]
5
+ end
6
+
7
+ def dump(obj)
8
+ ActiveSupport::JSON.encode(obj)
9
+ end
10
+
11
+ protected
12
+
13
+ def _load(string)
14
+ ActiveSupport::JSON.decode(string)
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ class Bsm::Model::Coders::MarshalColumn < Bsm::Model::Coders::AbstractColumn
2
+
3
+ def self.rescue_errors
4
+ [ ArgumentError, TypeError ]
5
+ end
6
+
7
+ def dump(obj)
8
+ Base64.encode64 Marshal.dump(obj)
9
+ end
10
+
11
+ protected
12
+
13
+ def _load(string)
14
+ Marshal.load(Base64.decode64(string))
15
+ end
16
+
17
+ end
@@ -49,7 +49,6 @@ module Bsm::Model::HasManySerialized
49
49
  klass.where(klass.primary_key => send(attribute_name))
50
50
  end
51
51
 
52
-
53
52
  model.redefine_method(attribute_name) do
54
53
  read_attribute(attribute_name)
55
54
  end if ActiveRecord::VERSION::STRING < "3.2.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsm-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-02 00:00:00.000000000Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abstract
16
- requirement: &19114100 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19114100
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activerecord
27
- requirement: &19113500 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 3.1.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *19113500
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.1.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: railties
38
- requirement: &19112820 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 3.1.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *19112820
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &19112280 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *19112280
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: sqlite3-ruby
60
- requirement: &19111520 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *19111520
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: shoulda-matchers
71
- requirement: &19110940 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,16 +101,25 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *19110940
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  description: ''
81
111
  email: dimitrij@blacksquaremedia.com
82
112
  executables: []
83
113
  extensions: []
84
114
  extra_rdoc_files: []
85
115
  files:
116
+ - lib/bsm/model/coders/json_column.rb
117
+ - lib/bsm/model/coders/marshal_column.rb
118
+ - lib/bsm/model/coders/abstract_column.rb
86
119
  - lib/bsm/model/abstract.rb
87
120
  - lib/bsm/model/locale/en.yml
88
121
  - lib/bsm/model/deletable.rb
122
+ - lib/bsm/model/coders.rb
89
123
  - lib/bsm/model/has_many_serialized.rb
90
124
  - lib/bsm/model/eager_descendants.rb
91
125
  - lib/bsm/model/sti_convertable.rb
@@ -113,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
147
  version: 1.3.6
114
148
  requirements: []
115
149
  rubyforge_project:
116
- rubygems_version: 1.8.10
150
+ rubygems_version: 1.8.24
117
151
  signing_key:
118
152
  specification_version: 3
119
153
  summary: BSM's very custom model extensions