Module: Syncdb

Defined in:
lib/syncdb.rb,
lib/synchronizator.rb

Defined Under Namespace

Classes: Synchronizator

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.major_versionObject



12
13
14
# File 'lib/syncdb.rb', line 12

def self.major_version
  version.split('.')[0].to_i
end

.minor_versionObject



16
17
18
# File 'lib/syncdb.rb', line 16

def self.minor_version
  version.split('.')[1].to_i
end

.patch_versionObject



20
21
22
# File 'lib/syncdb.rb', line 20

def self.patch_version
  version.split('.')[2].to_i
end

.sync(array_of_hashs, model_objects, model_name, &closure) ⇒ Object

Returt true, if syncronization passed

array_of_hashs - Array of Hash objects. Each hash should be like params from CGI in ActiveController

[
  {:attr_name => value},
  {:attr_name => value},
  {:attr_name => value},
]

model_objects - Array of objects, who should be syncronized. Should be like result of find method of Model:

Modelname.find :all

closure can get two variables: hash_item and model_item hash_item - it’s specimen of item array_of_hashs, model_item - specimen of item model_objects

Should return true or false If return true, hash_item and model_item is equals

array_of_hash = [

{:name => 'Harry', :surname => 'Potter', :age => 15},
{:name => 'Gendalf', :surname => 'Gray', :age => 524},
{:name => 'Gerold', :surname => 'Witcher', :age => 164},
{:name => 'Darth', :surname => 'Vader', :age => 50}

]<br /> Syncdb.sync array_of_hash, Person.all do |hash_item, model_item| do

(hash_item.surname == model_item.surname)

end



57
58
59
60
# File 'lib/syncdb.rb', line 57

def self.sync array_of_hashs, model_objects, model_name, &closure

  Syncdb::Synchronizator.sync array_of_hashs, model_objects, model_name, &closure
end

.versionObject

Returns the version string for the library.



8
9
10
# File 'lib/syncdb.rb', line 8

def self.version
  VERSION
end