Sha256: 21489a3a31ee6b3b910fe5f3336a5e9807fff8e9ac7fc9b4d5f4054d850bebff

Contents?: true

Size: 1 KB

Versions: 22

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

module Backup
  class Finder
    attr_accessor :trigger, :config

    ##
    # Initializes a new Backup::Finder object
    # and stores the path to the configuration file
    def initialize(trigger, config)
      @trigger = trigger.to_sym
      @config  = config
    end

    ##
    # Tries to find and load the configuration file and return the proper
    # backup model configuration (specified by the 'trigger')
    def find
      unless File.exist?(config)
        puts "Could not find a configuration file in '#{config}'."; exit
      end

      ##
      # Loads the backup configuration file
      instance_eval(File.read(config))

      ##
      # Iterates through all the instantiated backup models and returns
      # the one that matches the specified 'trigger'
      Backup::Model.all.each do |model|
        if model.trigger.eql?(trigger)
          return Backup::Model.current = model
        end
      end

      puts "Could not find trigger '#{trigger}' in '#{config}'."; exit
    end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
interu-backup-3.0.16 lib/backup/finder.rb
backup-3.0.16 lib/backup/finder.rb
backup-3.0.15 lib/backup/finder.rb
backup-3.0.14 lib/backup/finder.rb
backup-3.0.13 lib/backup/finder.rb
backup-3.0.12 lib/backup/finder.rb
backup-3.0.11 lib/backup/finder.rb
alg-backup-3.0.10 lib/backup/finder.rb
backup-3.0.10 lib/backup/finder.rb
backup-3.0.9 lib/backup/finder.rb
backup-3.0.8 lib/backup/finder.rb
backup-3.0.7 lib/backup/finder.rb
backup-3.0.6 lib/backup/finder.rb
backup-3.0.5 lib/backup/finder.rb
backup-3.0.4 lib/backup/finder.rb
backup-3.0.3 lib/backup/finder.rb
backup-3.0.2.build.0 lib/backup/finder.rb
backup-3.0.2 lib/backup/finder.rb
backup-3.0.1.build.0 lib/backup/finder.rb
backup-3.0.1 lib/backup/finder.rb