nsync 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -3,13 +3,11 @@ module Nsync
3
3
  module Consumer
4
4
  module ClassMethods
5
5
  def nsync_find(ids)
6
- nsync_opts = read_inheritable_attribute(:nsync_opts)
7
6
  all(:conditions => {nsync_opts[:id_key] => ids})
8
7
  end
9
8
 
10
9
  def nsync_add_data(consumer, event_type, filename, data)
11
10
  data = data.dup
12
- nsync_opts = read_inheritable_attribute(:nsync_opts)
13
11
  if nsync_opts[:id_key].to_s != "id"
14
12
  data[nsync_opts[:id_key].to_s] = data.delete("id")
15
13
  create(data)
@@ -31,7 +29,7 @@ module Nsync
31
29
  if event_type == :deleted
32
30
  destroy
33
31
  else
34
- nsync_opts = self.class.read_inheritable_attribute(:nsync_opts)
32
+ nsync_opts = self.class.nsync_opts
35
33
  if nsync_opts[:id_key].to_s != "id"
36
34
  data[nsync_opts[:id_key].to_s] = data.delete("id")
37
35
  else
@@ -6,18 +6,25 @@ module Nsync
6
6
  module ClassMethods
7
7
  # Makes this class an Nsync Consumer
8
8
  def nsync_consumer(opts={})
9
- nsync_opts = {:id_key => :source_id}.merge(opts)
10
- write_inheritable_attribute(:nsync_opts, nsync_opts)
9
+ self.nsync_opts = {:id_key => :source_id}.merge(opts)
11
10
  include Nsync::ActiveRecord::Consumer::InstanceMethods
12
11
  end
13
12
 
14
13
  def nsync_producer(opts={})
15
- nsync_opts = {:id_key => :id}.merge(opts)
16
- write_inheritable_attribute(:nsync_opts, nsync_opts)
14
+ self.nsync_opts = {:id_key => :id}.merge(opts)
17
15
  include Nsync::ActiveRecord::Consumer::InstanceMethods
18
16
  include Nsync::Producer::InstanceMethods
19
17
  include Nsync::ActiveRecord::Producer::InstanceMethods
20
18
  end
19
+
20
+ def nsync_opts=(hash_of_options)
21
+ @nsync_opts = hash_of_options
22
+ end
23
+
24
+ def nsync_opts
25
+ return @nsync_opts unless superclass && superclass.respond_to?(:nsync_opts)
26
+ @nsync_opts ||= superclass.nsync_opts.clone
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -3,15 +3,22 @@ module Nsync
3
3
  module ClassMethods
4
4
  # Makes this class an Nsync Consumer
5
5
  def nsync_consumer(opts={})
6
- nsync_opts = {:id_key => :source_id}.merge(opts)
7
- write_inheritable_attribute(:nsync_opts, nsync_opts)
6
+ self.nsync_opts = {:id_key => :source_id}.merge(opts)
8
7
  end
9
8
 
10
9
  def nsync_producer(opts={})
11
- nsync_opts = {:id_key => :id}.merge(opts)
12
- write_inheritable_attribute(:nsync_opts, nsync_opts)
10
+ self.nsync_opts = {:id_key => :id}.merge(opts)
13
11
  include Nsync::Producer::InstanceMethods
14
12
  end
13
+
14
+ def nsync_opts=(hash_of_options)
15
+ @nsync_opts = hash_of_options
16
+ end
17
+
18
+ def nsync_opts
19
+ return @nsync_opts unless superclass && superclass.respond_to?(:nsync_opts)
20
+ @nsync_opts ||= superclass.nsync_opts.clone
21
+ end
15
22
  end
16
23
  end
17
24
 
@@ -6,6 +6,14 @@ module Nsync
6
6
  string.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
7
7
  end
8
8
 
9
+ def self.underscore(camel_cased_word)
10
+ camel_cased_word.to_s.gsub(/::/, '/').
11
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
12
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
13
+ tr("-", "_").
14
+ downcase
15
+ end
16
+
9
17
  def self.constantize(string)
10
18
  names = string.split('::')
11
19
  names.shift if names.size == 0 || names.first.size == 0
@@ -2,7 +2,7 @@ module Nsync
2
2
  class Producer
3
3
  module InstanceMethods
4
4
  def nsync_write
5
- nsync_opts = self.class.read_inheritable_attribute(:nsync_opts)
5
+ nsync_opts = self.class.nsync_opts
6
6
  if !nsync_opts[:if] || nsync_opts[:if].call(self)
7
7
  Nsync.config.producer_instance.write_file(nsync_filename, to_nsync_hash)
8
8
  elsif Nsync.config.producer_instance.file_exists?(nsync_filename)
@@ -15,8 +15,8 @@ module Nsync
15
15
  end
16
16
 
17
17
  def nsync_filename
18
- nsync_opts = self.class.read_inheritable_attribute(:nsync_opts)
19
- File.join(self.class.to_s.underscore, "#{send(nsync_opts[:id_key])}.json")
18
+ nsync_opts = self.class.nsync_opts
19
+ File.join(CoreExtensions.underscore(self.class.to_s), "#{send(nsync_opts[:id_key])}.json")
20
20
  end
21
21
  end
22
22
  end
data/nsync.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nsync}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Hughes"]
12
- s.date = %q{2011-06-13}
12
+ s.date = %q{2011-06-30}
13
13
  s.description = %q{Nsync is designed to allow you to have a separate data
14
14
  processing app with its own data processing optimized database and a consumer
15
15
  app with its own database, while keeping the data as in sync as you want it.}
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
  ]
40
40
  s.homepage = %q{http://github.com/schleyfox/nsync}
41
41
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.4.0}
42
+ s.rubygems_version = %q{1.4.1}
43
43
  s.summary = %q{Keep your data processors and apps in sync}
44
44
  s.test_files = [
45
45
  "test/active_record_test.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsync
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Hughes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-13 00:00:00 -04:00
18
+ date: 2011-06-30 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements: []
161
161
 
162
162
  rubyforge_project:
163
- rubygems_version: 1.4.0
163
+ rubygems_version: 1.4.1
164
164
  signing_key:
165
165
  specification_version: 3
166
166
  summary: Keep your data processors and apps in sync