difference_update_seed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92f0898ad548bdd44affc3b82031d8323a99c145
4
+ data.tar.gz: 59d2c8ad879f66e1194a74786c166d470ba5c94a
5
+ SHA512:
6
+ metadata.gz: bc2260795c9ec92e6525796dbf2fa78465d5b180e932d87fbc0352fc5a71c2953d79f32e39beef6880d9d4b1154c5a2450e4586791002274eda31ac83ed2b650
7
+ data.tar.gz: 1de2f95e4ca1958afaa583159b96f329e3335db25c9b74b5914c248efc7c07774eff103e2a3f5f389b8bb9d3e26ea444df8a52d69d7d5ba656ec3c4860ca21cb
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in difference_update_seed.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 AKAMATSU Yuki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # DifferenceUpdateSeed
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'difference_update_seed'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install difference_update_seed
17
+
18
+ ## Usage
19
+
20
+ in db/seeds.rb
21
+
22
+ ```ruby
23
+ require 'difference_update_seed'
24
+ using DifferenceUpdateSeed
25
+
26
+ User.seed(:name) do |u|
27
+ u.name = 'AKAMATSU Yuki'
28
+ u.age = 27
29
+ end #=> Insert new record
30
+
31
+ User.seed(:name) do |u|
32
+ u.name = 'AKAMATSU Yuki'
33
+ u.age = 27
34
+ end #=> Do nothing
35
+
36
+ User.seed(:name) do |u|
37
+ u.name = 'AKAMATSU Yuki'
38
+ u.age = 28
39
+ end #=> Update 'AKAMATSU Yuki's age
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/ukstudio/difference_update_seed/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'difference_update_seed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "difference_update_seed"
8
+ spec.version = DifferenceUpdateSeed::VERSION
9
+ spec.authors = ["AKAMATSU Yuki"]
10
+ spec.email = ["y.akamatsu@ukstudio.jp"]
11
+ spec.summary = %q{Difference updating for db:seed}
12
+ spec.description = %q{Difference updating for db:seed}
13
+ spec.homepage = "http://github.com/ukstudio/difference_update_seed"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", ">= 1.0.0"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,28 @@
1
+ require "difference_update_seed/version"
2
+
3
+ module DifferenceUpdateSeed
4
+ refine ActiveRecord::Base.singleton_class do
5
+ def seed(*keys, &block)
6
+ unknown_columns = keys.to_a.map(&:to_s) - column_names
7
+ unless unknown_columns.empty?
8
+ fail ArgumentError, "Unknown columns: #{unknown_columns.join(',')}. Valid columns: #{column_names.join(',')}"
9
+ end
10
+
11
+ new_record = new(&block)
12
+ record = find_or_initialize_by(new_record.attributes.slice(*keys.map(&:to_s)))
13
+ record.tap(&block)
14
+
15
+ if record.new_record?
16
+ record.save!
17
+ puts "Insert new record #{record.attributes.to_s}"
18
+ else
19
+ if record.changed?
20
+ puts "Update record. ID: #{record.id}, #{record.changes}"
21
+ record.save!
22
+ else
23
+ puts "Do nothing. ID #{record.id}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module DifferenceUpdateSeed
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: difference_update_seed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - AKAMATSU Yuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Difference updating for db:seed
42
+ email:
43
+ - y.akamatsu@ukstudio.jp
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - difference_update_seed.gemspec
54
+ - lib/difference_update_seed.rb
55
+ - lib/difference_update_seed/version.rb
56
+ homepage: http://github.com/ukstudio/difference_update_seed
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Difference updating for db:seed
80
+ test_files: []