Class: Saseo::Models::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/saseo/models/base.rb

Direct Known Subclasses

Source::Base, Version

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.database_configObject



18
19
20
# File 'lib/saseo/models/base.rb', line 18

def database_config
  database_config_url || database_config_from_file
end

.database_config_from_fileObject



22
23
24
25
26
27
28
# File 'lib/saseo/models/base.rb', line 22

def database_config_from_file
  begin
    database_config_from_relative_path
  rescue
    database_config_from_load_path
  end
end

.database_config_from_load_pathObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/saseo/models/base.rb', line 34

def database_config_from_load_path
  config      = nil
  config_path = database_config_path
  $:.each do |load_path|
    begin
      config = YAML::load(File.open(File.expand_path File.join(load_path, config_path)))[Saseo.config.env]
      break
    rescue
    end
  end
  config
end

.database_config_from_relative_pathObject



30
31
32
# File 'lib/saseo/models/base.rb', line 30

def database_config_from_relative_path
  YAML::load(File.open(File.expand_path(database_config_path)))[Saseo.config.env]
end

.database_config_pathObject



10
11
12
# File 'lib/saseo/models/base.rb', line 10

def database_config_path
  Saseo.config.database_config_path
end

.database_config_urlObject



14
15
16
# File 'lib/saseo/models/base.rb', line 14

def database_config_url
  Saseo.config.database_url
end

.reconnect!Object



47
48
49
50
# File 'lib/saseo/models/base.rb', line 47

def reconnect!
  ActiveRecord::Base.clear_all_connections!
  ActiveRecord::Base.establish_connection
end

Instance Method Details

#changesObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/saseo/models/base.rb', line 65

def changes
  old_keys = old_data ? old_data.keys : []
  new_keys = new_data ? new_data.keys : []
  (old_keys | new_keys).reduce({}) do |changes, key|
    old_value = old_data ? old_data[key] : nil
    new_value = new_data ? new_data[key] : nil
    changes[key] = [old_value, new_value] if old_value != new_value
    changes
  end
end

#has_changes?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/saseo/models/base.rb', line 76

def has_changes?
  changes.any?
end