Class: ActsAsArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_archive.rb,
lib/acts_as_archive/gems.rb,
lib/acts_as_archive/adapters/sinatra.rb

Defined Under Namespace

Modules: Adapters, Base, DatabaseStatements, Gems

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



14
15
16
# File 'lib/acts_as_archive.rb', line 14

def configuration
  @configuration
end

.disabledObject

Returns the value of attribute disabled.



14
15
16
# File 'lib/acts_as_archive.rb', line 14

def disabled
  @disabled
end

Class Method Details

.deprecate(msg) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/acts_as_archive.rb', line 16

def deprecate(msg)
  if defined?(::ActiveSupport::Deprecation)
    ::ActiveSupport::Deprecation.warn msg
  else
    $stdout.puts msg
  end
end

.disable(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/acts_as_archive.rb', line 24

def disable(&block)
  @mutex ||= Mutex.new
  @mutex.synchronize do
    self.disabled = true
    block.call
  end
ensure
  self.disabled = false
end

.find(from) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/acts_as_archive.rb', line 34

def find(from)
  from = [ from ] unless from.is_a?(::Array)
  (@configuration || []).select do |hash|
    if from[0].is_a?(::String)
      from.include?(hash[:from].table_name)
    else
      from.include?(hash[:from])
    end
  end
end

.load_from_yaml(root) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/acts_as_archive.rb', line 45

def load_from_yaml(root)
  if File.exists?(yaml = "#{root}/config/acts_as_archive.yml")
    YAML.load(File.read(yaml)).each do |klass, config|
      klass = eval(klass) rescue nil
      if klass
        if (%w(class table) - config.last.keys).empty?
          options = {}
        else
          options = config.pop
        end
        config.each do |c|
          klass.acts_as_archive options.merge(c)
        end
      end
    end
  end
end

.move(config, where, merge_options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/acts_as_archive.rb', line 63

def move(config, where, merge_options={})
  options = config[:options].dup.merge(merge_options)
  if options[:conditions]
    options[:conditions] += " AND #{where}"
  elsif where
    options[:conditions] = where
  end
  config[:from].move_to(config[:to], options)
end

.update(*args) ⇒ Object



73
74
75
# File 'lib/acts_as_archive.rb', line 73

def update(*args)
  deprecate "ActsAsArchive.update is deprecated and no longer necessary."
end