sequel-string_nilifier 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTQzMjJiOTViMjExMGI0MTk3N2RhZTJiNzM4NWFkYzQ1YjMxZTU0OQ==
5
+ data.tar.gz: !binary |-
6
+ NDZmZDdiMTQxMWIzM2VkNTNiOGUyZDkwMGM4MTMxMzQ0YjM3MDdhNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjczMmEzZDdlOTMyMjhiYjcwNTU4MjY2NjI3Yzc5ZjM5ZGJmZjgyZTZlZGE1
10
+ N2E0ZmVhMGJhZTg1MjI2MDNlOTk3MTI5MDdlYzdhOTgxYzUwZTU4ODAwMTlm
11
+ OTIxNjM2YzFmODZkMWMwYjA5OGI4Yjg1MGIwMDdjNTBlYTk1MGQ=
12
+ data.tar.gz: !binary |-
13
+ NzY5MmYzMWRkZjM1MDljNmUyNDU2ZjM4MThiMjdkNDIzMWNkMWExNjhmMzA1
14
+ NTNlYTc2MzkyYThkZDExOGZhN2Q2MGE4NTM2NGVjOWQ2NjM5OWNhOWM1Yzcw
15
+ ZjE0NjUyYTlkZDFmODdmYTNmNTAxODdiYzhlNjNkMjBkMjAwY2Y=
@@ -1,7 +1,7 @@
1
1
  module Sequel
2
2
  module Plugins
3
3
  module StringNilifier
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,34 +1,32 @@
1
1
  module Sequel
2
2
  module Plugins
3
3
  module StringNilifier
4
+ def self.apply(model)
5
+ model.plugin(:input_transformer, :string_nilifier) do |v|
6
+ if v.is_a?(String) && !v.is_a?(SQL::Blob) && v.strip.empty?
7
+ nil
8
+ else
9
+ v
10
+ end
11
+ end
12
+ end
13
+
4
14
  # Set blob columns as skipping nilifying when plugin is loaded.
5
15
  def self.configure(model)
6
- model.instance_variable_set(:@skipped_string_nilifier_columns, [])
7
- model.send(:set_skipped_string_nilifying_columns)
16
+ model.instance_eval{set_skipped_string_nilifying_columns if @dataset}
8
17
  end
9
18
 
10
19
  module ClassMethods
11
- # Copy skipped nilifying columns from superclass into subclass.
12
- def inherited(subclass)
13
- subclass.instance_variable_set(:@skipped_string_nilifier_columns, @skipped_string_nilifier_columns.dup)
14
- super
15
- end
16
-
17
- # Set blob columns as skipping nilifying when plugin is loaded.
18
- def set_dataset(*)
19
- res = super
20
- set_skipped_string_nilifying_columns
21
- res
22
- end
20
+ Plugins.after_set_dataset(self, :set_skipped_string_nilifying_columns)
23
21
 
24
22
  # Skip nilifying for the given columns.
25
23
  def skip_string_nilifying(*columns)
26
- @skipped_string_nilifier_columns.concat(columns).uniq!
24
+ skip_input_transformer(:string_nilifier, *columns)
27
25
  end
28
26
 
29
27
  # Return true if the column should not have values stripped.
30
28
  def skip_string_nilifying?(column)
31
- @skipped_string_nilifier_columns.include?(column)
29
+ skip_input_transformer?(:string_nilifier, column)
32
30
  end
33
31
 
34
32
  private
@@ -41,20 +39,6 @@ module Sequel
41
39
  end
42
40
  end
43
41
  end
44
-
45
- module InstanceMethods
46
- # Strip value if it is a non-blob string and the model hasn't been set
47
- # to skip nilifying for the column, before attempting to assign
48
- # it to the model's values.
49
- def nil_string?(k,str)
50
- str.is_a?(String) && !str.is_a?(SQL::Blob) && str.strip.empty? && !model.skip_string_nilifying?(k)
51
- end
52
-
53
- def []=(k, v)
54
- v = nil if nil_string? k, v
55
- super(k, v)
56
- end
57
- end
58
42
  end
59
43
  end
60
44
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "sequel"
21
+ spec.add_runtime_dependency "sequel", "~> 3.48.0"
22
22
 
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "rspec"
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Sequel::Plugins::StringNilifier do
4
4
  before do
5
- @db = Sequel::Database.new
5
+ @db = Sequel.mock
6
6
  @c = Class.new(Sequel::Model(@db[:test]))
7
7
  @c.columns :name, :b
8
8
  @c.db_schema[:b][:type] = :blob
@@ -58,6 +58,7 @@ describe Sequel::Plugins::StringNilifier do
58
58
  it "should work correctly for dataset changes" do
59
59
  c = Class.new(Sequel::Model(@db[:test]))
60
60
  c.plugin :string_nilifier
61
+ def @db.supports_schema_parsing?() true end
61
62
  def @db.schema(*) [[:name, {}], [:b, {:type=>:blob}]] end
62
63
  c.set_dataset(@db[:test2])
63
64
  o = c.new
data/spec/spec_helper.rb CHANGED
@@ -16,9 +16,10 @@ class << Sequel::Model
16
16
  end
17
17
 
18
18
  Sequel::Model.use_transactions = false
19
- Sequel::Model.cache_anonymous_models = false
19
+ Sequel.cache_anonymous_models = false
20
20
 
21
21
  db = Sequel.mock(:fetch=>{:id => 1, :x => 1}, :numrows=>1, :autoid=>proc{|sql| 10})
22
22
  def db.schema(*) [[:id, {:primary_key=>true}]] end
23
23
  def db.reset() sqls end
24
+ def db.supports_schema_parsing?() true end
24
25
  Sequel::Model.db = MODEL_DB = db
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-string_nilifier
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.1
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jonathan Tron
@@ -10,56 +9,50 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-07 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: sequel
17
15
  requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
22
- none: false
23
- type: :runtime
19
+ version: 3.48.0
24
20
  version_requirements: !ruby/object:Gem::Requirement
25
21
  requirements:
26
- - - ! '>='
22
+ - - ~>
27
23
  - !ruby/object:Gem::Version
28
- version: '0'
29
- none: false
24
+ version: 3.48.0
25
+ type: :runtime
30
26
  prerelease: false
27
+ name: sequel
31
28
  - !ruby/object:Gem::Dependency
32
- name: rake
33
29
  requirement: !ruby/object:Gem::Requirement
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
- none: false
39
- type: :development
40
34
  version_requirements: !ruby/object:Gem::Requirement
41
35
  requirements:
42
36
  - - ! '>='
43
37
  - !ruby/object:Gem::Version
44
38
  version: '0'
45
- none: false
39
+ type: :development
46
40
  prerelease: false
41
+ name: rake
47
42
  - !ruby/object:Gem::Dependency
48
- name: rspec
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
- none: false
55
- type: :development
56
48
  version_requirements: !ruby/object:Gem::Requirement
57
49
  requirements:
58
50
  - - ! '>='
59
51
  - !ruby/object:Gem::Version
60
52
  version: '0'
61
- none: false
53
+ type: :development
62
54
  prerelease: false
55
+ name: rspec
63
56
  description: Sequel plugin to store empty string as nil
64
57
  email:
65
58
  - jonathan.tron@metrilio.com
@@ -82,6 +75,7 @@ files:
82
75
  homepage: ''
83
76
  licenses:
84
77
  - MIT
78
+ metadata: {}
85
79
  post_install_message:
86
80
  rdoc_options: []
87
81
  require_paths:
@@ -90,25 +84,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
84
  requirements:
91
85
  - - ! '>='
92
86
  - !ruby/object:Gem::Version
93
- segments:
94
- - 0
95
- hash: -1606853858529528596
96
87
  version: '0'
97
- none: false
98
88
  required_rubygems_version: !ruby/object:Gem::Requirement
99
89
  requirements:
100
90
  - - ! '>='
101
91
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
- hash: -1606853858529528596
105
92
  version: '0'
106
- none: false
107
93
  requirements: []
108
94
  rubyforge_project:
109
- rubygems_version: 1.8.25
95
+ rubygems_version: 2.0.3
110
96
  signing_key:
111
- specification_version: 3
97
+ specification_version: 4
112
98
  summary: Sequel plugin to store empty string as nil
113
99
  test_files:
114
100
  - spec/sequel/plugins/string_nilifier_spec.rb