Class: Logical::Naf::Application

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/models/logical/naf/application.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(naf_app) ⇒ Application

Returns a new instance of Application.



22
23
24
# File 'app/models/logical/naf/application.rb', line 22

def initialize(naf_app)
  @app = naf_app
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



52
53
54
55
56
57
58
# File 'app/models/logical/naf/application.rb', line 52

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'app/models/logical/naf/application.rb', line 5

def app
  @app
end

Class Method Details

.search(search) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/logical/naf/application.rb', line 26

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

Instance Method Details

#commandObject



48
49
50
# File 'app/models/logical/naf/application.rb', line 48

def command
  @app.command
end

#to_hashObject



44
45
46
# File 'app/models/logical/naf/application.rb', line 44

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