Class: Logical::Naf::Application
- Inherits:
-
Object
- Object
- Logical::Naf::Application
- 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
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Class Method Summary collapse
Instance Method Summary collapse
- #affinities ⇒ Object
- #application_run_group_name ⇒ Object
- #command ⇒ Object
- #enqueue_backlogs ⇒ Object
-
#initialize(naf_app) ⇒ Application
constructor
A new instance of Application.
- #method_missing(method_name, *arguments, &block) ⇒ Object
- #prerequisites ⇒ Object
- #run_interval ⇒ Object
- #run_start_minute ⇒ Object
- #run_time ⇒ Object
- #to_hash ⇒ Object
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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/logical/naf/application.rb', line 134 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
#app ⇒ Object (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 66 67 |
# 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) ~ ?", Regexp.escape(search[field].downcase)] ) else application_scope.where(["lower(#{field}) ~ ?", Regexp.escape(search[field].downcase)]) end end end application_scope.map{ |physical_app| new(physical_app) } end |
Instance Method Details
#affinities ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/logical/naf/application.rb', line 161 def affinities if @app.application_schedule.try(:application_schedule_affinity_tabs).present? @app.application_schedule.application_schedule_affinity_tabs.map do |tab| if tab.affinity_short_name.present? if tab.affinity_parameter.present? && tab.affinity_parameter > 0 tab.affinity_short_name + "(#{tab.affinity_parameter})" else tab.affinity_short_name end else tab.affinity_classification_name + '_' + tab.affinity_name end end.join(", \n") end end |
#application_run_group_name ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'app/models/logical/naf/application.rb', line 124 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 |
#command ⇒ Object
73 74 75 |
# File 'app/models/logical/naf/application.rb', line 73 def command @app.command end |
#enqueue_backlogs ⇒ Object
157 158 159 |
# File 'app/models/logical/naf/application.rb', line 157 def enqueue_backlogs application_schedule.try(:enqueue_backlogs) end |
#prerequisites ⇒ Object
116 117 118 119 120 121 122 |
# File 'app/models/logical/naf/application.rb', line 116 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_interval ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/logical/naf/application.rb', line 97 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_minute ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/logical/naf/application.rb', line 77 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_time ⇒ Object
90 91 92 93 94 95 |
# File 'app/models/logical/naf/application.rb', line 90 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_hash ⇒ Object
69 70 71 |
# File 'app/models/logical/naf/application.rb', line 69 def to_hash Hash[ COLUMNS.map{ |m| [m, send(m)] } ] end |