Sha256: 0c12ba2186925e1441e66e29e3eb0dbc84245166d3df201f9062332af7f331d3

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

module Logical
  module Naf
    class Application

      attr_reader :app

      include ActionView::Helpers::TextHelper

      COLUMNS = [:id,
                 :title,
                 :short_name,
                 :script_type_name,
                 :application_schedules,
                 :deleted]

      FILTER_FIELDS = [:deleted]

      SEARCH_FIELDS = [:title,
                       :command,
                       :short_name]

      def initialize(naf_app)
        @app = naf_app
      end

      def self.search(search)
        application_scope = ::Naf::Application.order("id desc")

        FILTER_FIELDS.each do |field|
          if search.present? and search[field].present?
            application_scope = application_scope.where(field => search[field])
          end
        end

        SEARCH_FIELDS.each do |field|
          if search.present? and search[field].present?
            application_scope = application_scope.where(["lower(#{field}) ~ ?", Regexp.escape(search[field].downcase)])
          end
        end

        application_scope.map{ |physical_app| new(physical_app) }
      end

      def to_hash
        Hash[ COLUMNS.map{ |m| [m, send(m)] } ]
      end

      def command
        @app.command
      end

      def method_missing(method_name, *arguments, &block)
        if @app.respond_to?(method_name)
          @app.send(method_name, *arguments, &block)
        else
          super
        end
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
naf-2.1.13 app/models/logical/naf/application.rb
naf-2.1.12 app/models/logical/naf/application.rb
naf-2.1.11 app/models/logical/naf/application.rb
naf-2.1.10 app/models/logical/naf/application.rb
naf-2.1.9 app/models/logical/naf/application.rb
naf-2.1.8 app/models/logical/naf/application.rb
naf-2.1.6 app/models/logical/naf/application.rb
naf-2.1.5 app/models/logical/naf/application.rb
naf-2.1.4 app/models/logical/naf/application.rb
naf-2.1.3 app/models/logical/naf/application.rb
naf-2.1.2 app/models/logical/naf/application.rb
naf-2.1.1 app/models/logical/naf/application.rb
naf-2.1.0 app/models/logical/naf/application.rb