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_run_group_name,
:application_run_group_restriction_name,
:application_run_group_limit,
:enabled,
:enqueue_backlogs,
:run_time,
:affinities,
:prerequisites,
:deleted,
:visible]
FILTER_FIELDS =
[:deleted,
:enabled,
:visible]
SEARCH_FIELDS =
[:title,
:application_run_group_name,
: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.



33
34
35
# File 'app/models/logical/naf/application.rb', line 33

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



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/models/logical/naf/application.rb', line 132

def method_missing(method_name, *arguments, &block)
  case method_name
  when :application_run_group_restriction_name,
       :application_run_group_name,
       :run_start_minute,
       :priority,
       :application_run_group_limit,
       :visible,
       :enabled
    if schedule = @app.application_schedule
      schedule.send(method_name, *arguments, &block)
    else
      nil
    end
  else
    if @app.respond_to?(method_name)
      @app.send(method_name, *arguments, &block)
    else
      super
    end
  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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/logical/naf/application.rb', line 37

def self.search(search)
  application_scope = ::Naf::Application.
    joins("LEFT JOIN #{::Naf.schema_name}.application_schedules ON #{::Naf.schema_name}.application_schedules.application_id = #{::Naf.schema_name}.applications.id").
      order("id desc")

  FILTER_FIELDS.each do |field|
    if search.present? and search[field].present?
      application_scope =
      if field == :enabled || field == :visible
        application_scope.where(application_schedules: { field => search[field] })
      else
        application_scope.where(field => search[field])
      end
    end
  end

  SEARCH_FIELDS.each do |field|
    if search.present? and search[field].present?
      application_scope =
      if field == :application_run_group_name
        application_scope.where(["lower(#{::Naf.schema_name}.application_schedules.application_run_group_name) ~ ?", search[field].downcase])
      else
        application_scope.where(["lower(#{field}) ~ ?", search[field].downcase])
      end
    end
  end

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

Instance Method Details

#affinitiesObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'app/models/logical/naf/application.rb', line 159

def affinities
  affinity_tab_records = @app.application_schedule.try(:application_schedule_affinity_tabs)
  return "" if affinity_tab_records.nil?

  affinity_tabs = ""
  affinity_tab_records.each do |tab|
    if tab.affinity.affinity_short_name.present?
      affinity_tabs << tab.affinity.affinity_short_name
    else
      affinity_tabs << tab.affinity.affinity_name
    end

    if tab.affinity_parameter.present? && tab.affinity_parameter > 0
      affinity_tabs << "(#{tab.affinity_parameter}), "
    else
      affinity_tabs << ", "
    end
  end

  affinity_tabs[0..-3]
end

#application_run_group_nameObject



122
123
124
125
126
127
128
129
130
# File 'app/models/logical/naf/application.rb', line 122

def application_run_group_name
  if schedule = @app.application_schedule
    if schedule.application_run_group_name.blank?
      "not set"
    else
      schedule.application_run_group_name
    end
  end
end

#commandObject



71
72
73
# File 'app/models/logical/naf/application.rb', line 71

def command
  @app.command
end

#enqueue_backlogsObject



155
156
157
# File 'app/models/logical/naf/application.rb', line 155

def enqueue_backlogs
  application_schedule.try(:enqueue_backlogs)
end

#prerequisitesObject



114
115
116
117
118
119
120
# File 'app/models/logical/naf/application.rb', line 114

def prerequisites
  if schedule = @app.application_schedule and schedule.application_schedule_prerequisites.present?
    schedule.prerequisites.map do |schedule_prerequisite|
      schedule_prerequisite.application.short_name_if_it_exist
    end.join(", \n")
  end
end

#run_intervalObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/logical/naf/application.rb', line 95

def run_interval
  output = ""
  if schedule = @app.application_schedule and schedule.run_interval.present?
    time = schedule.run_interval
    output =
    if time == 0
      "run constantly"
    elsif time < 60
      pluralize(time, "minute")
    elsif time % 60 == 0
      pluralize(time / 60, "hour")
    else
      pluralize(time / 60, "hour") + ', ' + pluralize(time % 60, "minute")
    end
  end

  output
end

#run_start_minuteObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/logical/naf/application.rb', line 75

def run_start_minute
  output = ""
  if schedule = @app.application_schedule and schedule.run_start_minute.present?
    minutes = schedule.run_start_minute % 60
    hours =   schedule.run_start_minute / 60
    output << hours.to_s + ":"
    output << "%02d" % minutes
    output = Time.parse(output).strftime("%I:%M %p")
  end

  return output
end

#run_timeObject



88
89
90
91
92
93
# File 'app/models/logical/naf/application.rb', line 88

def run_time
  run_time = run_start_minute.blank? ? run_interval : run_start_minute
  run_time = "not scheduled" if run_time.blank?

  run_time
end

#to_hashObject



67
68
69
# File 'app/models/logical/naf/application.rb', line 67

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