sneaky-save 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # sneaky-save
2
+
3
+ ActiveRecord extension. Allows to save record without calling callbacks and validations.
4
+
5
+ ## Installing
6
+ ```
7
+ $ gem install sneaky-save
8
+ ```
9
+
10
+ Or put in your gemfile for latest version:
11
+ ```ruby
12
+ gem 'sneaky-save', git: 'git://github.com/partyearth/sneaky-save.git'
13
+ ```
14
+
15
+ ## Using
16
+ ```ruby
17
+ # Update
18
+ @existed_record.sneaky_save
19
+
20
+ # Insert
21
+ Model.new.sneaky_save
22
+ ```
23
+
24
+ ## Running specs
25
+ - Clone the repo
26
+ - run `bundle exec rake spec`
27
+
28
+ ## Contributing to sneaky-save
29
+
30
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
31
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
32
+ - Fork the project
33
+ - Start a feature/bugfix branch
34
+ - Commit and push until you are happy with your contribution
35
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
36
+ - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
37
+
38
+ ## Copyright
39
+
40
+ Copyright (c) 2011 PartyEarth LLC. See LICENSE.txt for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/sneaky-save.rb CHANGED
@@ -3,11 +3,9 @@
3
3
  # mailto:kgoslar@partyearth.com
4
4
  #++
5
5
  module SneakySave
6
- extend ActiveSupport::Concern
7
6
 
8
7
  # Saves record without running callbacks/validations.
9
8
  # Returns true if any record is changed.
10
- #
11
9
  # @note - Does not reload updated record by default.
12
10
  # - Does not save associated collections.
13
11
  # - Saves only belongs_to relations.
@@ -23,8 +21,7 @@ module SneakySave
23
21
 
24
22
  protected
25
23
 
26
- # Makes INSERT query in database without running any callbacks.
27
- #
24
+ # Makes INSERT query in database without running any callbacks
28
25
  # @return [false, true]
29
26
  def sneaky_create
30
27
  if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name)
@@ -33,6 +30,11 @@ module SneakySave
33
30
 
34
31
  attributes_values = send :arel_attributes_values
35
32
 
33
+ # Remove the id field for databases like Postgres which will raise an error on id being NULL
34
+ if self.id.nil? && !connection.prefetch_primary_key?(self.class.table_name)
35
+ attributes_values.reject! { |key,_| key.name == 'id' }
36
+ end
37
+
36
38
  new_id = if attributes_values.empty?
37
39
  self.class.unscoped.insert connection.empty_insert_statement_value
38
40
  else
@@ -43,13 +45,12 @@ module SneakySave
43
45
  !!(self.id ||= new_id)
44
46
  end
45
47
 
46
- # Makes update query without running callbacks.
47
- #
48
+ # Makes update query without running callbacks
48
49
  # @return [false, true]
49
50
  def sneaky_update
50
51
 
51
52
  # Handle no changes.
52
- return true unless changes.any?
53
+ return true if changes.empty?
53
54
 
54
55
  # Here we have changes --> save them.
55
56
  pk = self.class.primary_key
data/sneaky-save.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sneaky-save}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sergei Zinin", "Kevin Goslar"]
9
- s.date = %q{2011-10-18}
9
+ s.date = %q{2013-02-21}
10
10
  s.description = %q{ActiveRecord extension. Allows to save record without calling callbacks and validations.}
11
11
  s.email = %q{kgoslar@partyearth.com}
12
12
  s.extra_rdoc_files = [
13
13
  "LICENSE.txt",
14
- "README.rdoc"
14
+ "README.md"
15
15
  ]
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.homepage = %q{http://github.com/partyearth/sneaky-save}
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "active_record"
2
2
  require "logger"
3
3
  require "rspec"
4
- require "sneaky_save"
4
+ require "sneaky-save"
5
5
 
6
6
  RSpec.configure { |config| config.mock_with :rspec }
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sneaky-save
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-18 00:00:00.000000000 Z
13
+ date: 2013-02-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -67,13 +67,13 @@ executables: []
67
67
  extensions: []
68
68
  extra_rdoc_files:
69
69
  - LICENSE.txt
70
- - README.rdoc
70
+ - README.md
71
71
  files:
72
72
  - .gitignore
73
73
  - Gemfile
74
74
  - Gemfile.lock
75
75
  - LICENSE.txt
76
- - README.rdoc
76
+ - README.md
77
77
  - Rakefile
78
78
  - VERSION
79
79
  - lib/sneaky-save.rb
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 1.8.19
105
+ rubygems_version: 1.8.25
106
106
  signing_key:
107
107
  specification_version: 3
108
108
  summary: Allows to save record without calling callbacks and validations.
data/README.rdoc DELETED
@@ -1,31 +0,0 @@
1
- = sneaky-save
2
-
3
- ActiveRecord extension. Allows to save record without calling callbacks and validations.
4
-
5
- == Installing
6
- # gem install sneaky-save
7
-
8
- == Using
9
- # Update
10
- @existed_record.sneaky_save
11
-
12
- # Insert
13
- Model.new.sneaky_save
14
-
15
- == Running specs
16
- * Clone the repo
17
- * run `bundle exec rake spec`
18
-
19
- == Contributing to sneaky-save
20
-
21
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
22
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
23
- * Fork the project
24
- * Start a feature/bugfix branch
25
- * Commit and push until you are happy with your contribution
26
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
27
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
28
-
29
- == Copyright
30
-
31
- Copyright (c) 2011 PartyEarth LLC. See LICENSE.txt for details.