bsm-models 0.5.4 → 0.5.5

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.
@@ -1,3 +1,5 @@
1
+ require 'bsm/model/coders/json_column'
2
+
1
3
  module Bsm::Model::HasManySerialized
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -9,25 +11,6 @@ module Bsm::Model::HasManySerialized
9
11
 
10
12
  end
11
13
 
12
- class Coder
13
-
14
- def dump(obj)
15
- ActiveSupport::JSON.encode(obj)
16
- end
17
-
18
- def load(value)
19
- return [] if value.nil?
20
- return value unless value.is_a?(String)
21
-
22
- obj = ActiveSupport::JSON.decode(value) || []
23
- unless obj.is_a?(Array)
24
- raise ActiveRecord::SerializationTypeMismatch, "Attribute was supposed to be an Array, but was a #{obj.class}"
25
- end
26
- obj
27
- end
28
-
29
- end
30
-
31
14
  class Builder < ActiveRecord::Associations::Builder::Association
32
15
 
33
16
  def build
@@ -39,7 +22,7 @@ module Bsm::Model::HasManySerialized
39
22
  protected
40
23
 
41
24
  def serialize_attribute
42
- model.serialize attribute_name, Coder.new
25
+ model.serialize attribute_name, ::Bsm::Model::Coders::JsonColumn.new(Array)
43
26
  end
44
27
 
45
28
  def define_readers
@@ -63,11 +46,11 @@ module Bsm::Model::HasManySerialized
63
46
  next if record.is_a?(klass)
64
47
  raise ActiveRecord::AssociationTypeMismatch, "#{klass.name} expected, got #{record.class}"
65
48
  end
66
- write_attribute attribute_name, records.map(&:id)
49
+ write_attribute attribute_name, records.map(&:id).sort
67
50
  end
68
51
 
69
52
  model.redefine_method("#{attribute_name}=") do |values|
70
- send "#{name}=", klass.where(klass.primary_key => Array.wrap(values)).select(:id).to_a
53
+ send "#{name}=", klass.where(klass.primary_key => Array.wrap(values)).select(:id).to_a.sort
71
54
  end
72
55
  end
73
56
 
@@ -20,7 +20,7 @@ module Bsm::Model::StiConvertable
20
20
  klass = real_descendants.find {|k| k.kind == kind } || fallback_descendant
21
21
  return super if klass == self
22
22
 
23
- klass.with_scope(respond_to?(:current_scope) ? current_scope : current_scoped_methods) do # AR 3.0 compatibility
23
+ klass.with_scope(methods.include?(:current_scope) ? current_scope : current_scoped_methods) do # AR 3.0 compatibility
24
24
  klass.new(attributes, *args, &block)
25
25
  end
26
26
  end
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.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-06 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abstract
@@ -113,20 +113,20 @@ executables: []
113
113
  extensions: []
114
114
  extra_rdoc_files: []
115
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
119
- - lib/bsm/model/abstract.rb
116
+ - lib/bsm/model.rb
117
+ - lib/bsm/model/editable.rb
120
118
  - lib/bsm/model/locale/en.yml
121
- - lib/bsm/model/deletable.rb
119
+ - lib/bsm/model/abstract.rb
122
120
  - lib/bsm/model/coders.rb
123
- - lib/bsm/model/has_many_serialized.rb
121
+ - lib/bsm/model/deletable.rb
124
122
  - lib/bsm/model/eager_descendants.rb
123
+ - lib/bsm/model/has_many_serialized.rb
125
124
  - lib/bsm/model/sti_convertable.rb
126
- - lib/bsm/model/editable.rb
127
- - lib/bsm/model.rb
128
- - lib/bsm_models.rb
125
+ - lib/bsm/model/coders/marshal_column.rb
126
+ - lib/bsm/model/coders/abstract_column.rb
127
+ - lib/bsm/model/coders/json_column.rb
129
128
  - lib/bsm-models.rb
129
+ - lib/bsm_models.rb
130
130
  homepage: https://github.com/bsm/models
131
131
  licenses: []
132
132
  post_install_message:
@@ -147,8 +147,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: 1.3.6
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 1.8.24
150
+ rubygems_version: 1.8.25
151
151
  signing_key:
152
152
  specification_version: 3
153
153
  summary: BSM's very custom model extensions
154
154
  test_files: []
155
+ has_rdoc: