Sha256: 5741c1fc2853a9c5688adbd750f4349037e4c1d9768d3f09734e272e1b32c9bc

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

module Naf
  class ApplicationType < NafBase
    # Protect from mass-assignment issue
    attr_accessible :enabled,
                    :script_type_name,
                    :description,
                    :invocation_method

    SCRIPT_RUNNER = "#{Gem.ruby} #{Rails.root}/script/rails runner"

    #---------------------
    # *** Associations ***
    #+++++++++++++++++++++

    has_many :applications,
      class_name: "::Naf::Application"
    has_many :historical_jobs,
      class_name: "::Naf::HistoricalJob"

    #--------------------
    # *** Validations ***
    #++++++++++++++++++++

    validates :script_type_name,
              :invocation_method, presence: true

    #-------------------------
    # *** Instance Methods ***
    #+++++++++++++++++++++++++

    def spawn(job)
      self.send(invocation_method.to_sym, job)
    end

    def invoke(job, command)
      ENV['NAF_JOB_ID'] = job.id.to_s
      Open4::popen4(command)
    end

    def rails_invocator(job)
      invoke(job, SCRIPT_RUNNER + " " + job.command)
    end

    def bash_command_invocator(job)
      invoke(job, job.command)
    end

    def bash_script_invocator(job)
      invoke(job, job.command)
    end

    def ruby_script_invocator(job)
      invoke(job, job.command)
    end

    def self.rails
      @rails ||= find_by_script_type_name('rails')
    end

    def self.ruby
      @ruby ||= find_by_script_type_name('ruby')
    end

    def self.bash_command
      @bash_command ||= find_by_script_type_name('bash command')
    end

    def self.bash_script
      @bash_script ||= find_by_script_type_name('bash script')
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
naf-2.1.3 app/models/naf/application_type.rb
naf-2.1.2 app/models/naf/application_type.rb
naf-2.1.1 app/models/naf/application_type.rb
naf-2.1.0 app/models/naf/application_type.rb
naf-2.0.4 app/models/naf/application_type.rb
naf-2.0.3 app/models/naf/application_type.rb
naf-2.0.2 app/models/naf/application_type.rb
naf-2.0.1 app/models/naf/application_type.rb
naf-2.0.0 app/models/naf/application_type.rb