Module: Nsync::Producer::InstanceMethods

Defined in:
lib/nsync/producer/methods.rb

Instance Method Summary collapse

Instance Method Details

#nsync_destroyObject



13
14
15
# File 'lib/nsync/producer/methods.rb', line 13

def nsync_destroy
  Nsync.config.producer_instance.remove_file(nsync_filename)
end

#nsync_filenameObject



17
18
19
20
# File 'lib/nsync/producer/methods.rb', line 17

def nsync_filename
  nsync_opts = self.class.nsync_opts
  File.join(CoreExtensions.underscore(self.class.to_s), "#{send(nsync_opts[:id_key])}.json")
end

#nsync_writeObject



4
5
6
7
8
9
10
11
# File 'lib/nsync/producer/methods.rb', line 4

def nsync_write
  nsync_opts = self.class.nsync_opts
  if !nsync_opts[:if] || nsync_opts[:if].call(self)
    Nsync.config.producer_instance.write_file(nsync_filename, to_nsync_hash)
  elsif Nsync.config.producer_instance.file_exists?(nsync_filename)
    nsync_destroy
  end
end