antonjenkins-model_sync 0.1.3 → 0.1.4

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.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/lib/model_sync.rb +10 -7
  3. data/model_sync.gemspec +2 -2
  4. metadata +2 -2
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('model_sync', '0.1.3') do |p|
5
+ Echoe.new('model_sync', '0.1.4') do |p|
6
6
  p.description = "Sync changes to an ActiveRecord model to another model"
7
7
  p.url = "http://github.com/antonjenkins/model_sync"
8
8
  p.author = "Anton Jenkins"
@@ -32,13 +32,16 @@ module ModelSync
32
32
  def method_missing(id, *args, &block)
33
33
  case(id.to_s)
34
34
  when /^create_#{self.class.slave_model_name}$/
35
- # If we've received a create_{slave_model} call then create a new instance of it and sync to it
36
- new_instance = self.class.slave_model_class.new
37
- perform_sync(new_instance)
38
- # Save the new instance so that its primary key is generated and pass this value onto our master model
39
- new_instance.save
40
- self.update_attribute(self.class.relationship.keys.first, new_instance.read_attribute(self.class.relationship.values.first.to_s))
41
- when /^synced_with_#{self.class.slave_model_name}\?$/
35
+ # Only create a new slave if one doesn't already exist
36
+ unless find_slave_instance
37
+ # If we've received a create_{slave_model} call then create a new instance of it and sync to it
38
+ new_instance = self.class.slave_model_class.new
39
+ perform_sync(new_instance)
40
+ # Save the new instance so that its primary key is generated and pass this value onto our master model
41
+ new_instance.save
42
+ self.update_attribute(self.class.relationship.keys.first, new_instance.read_attribute(self.class.relationship.values.first.to_s))
43
+ end
44
+ when /^synch?ed_with_#{self.class.slave_model_name}\?$/
42
45
  !!find_slave_instance
43
46
  else
44
47
  super
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{model_sync}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Anton Jenkins"]
9
- s.date = %q{2009-07-07}
9
+ s.date = %q{2009-07-20}
10
10
  s.description = %q{Sync changes to an ActiveRecord model to another model}
11
11
  s.email = %q{info@pixellatedvisions.com}
12
12
  s.extra_rdoc_files = ["lib/model_sync.rb", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antonjenkins-model_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Jenkins
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-07 00:00:00 -07:00
12
+ date: 2009-07-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15