Class: RakeUi::RakeTask
- Inherits:
-
Object
- Object
- RakeUi::RakeTask
- Defined in:
- app/models/rake_ui/rake_task.rb
Instance Attribute Summary collapse
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
- .all ⇒ Object
- .find_by_id(id) ⇒ Object
- .from_safe_identifier(id) ⇒ Object
- .internal ⇒ Object
- .load ⇒ Object
- .to_safe_identifier(id) ⇒ Object
Instance Method Summary collapse
-
#build_rake_command(args: nil, environment: nil) ⇒ Object
returns an invokable rake command FOO=bar rake create_something rake create_something rake create_something.
- #call(args: nil, environment: nil) ⇒ Object
- #id ⇒ Object
-
#initialize(task) ⇒ RakeTask
constructor
A new instance of RakeTask.
-
#internal_task? ⇒ Boolean
thinking this is the sanest way to discern application vs gem defined tasks (like rails, devise etc).
- #is_internal_task ⇒ Object
-
#rake_definition_file ⇒ Object
actions will be something like #<Proc:0x000055a2737fe778@/some/rails/app/lib/tasks/auto_annotate_models.rake:4>.
Constructor Details
#initialize(task) ⇒ RakeTask
Returns a new instance of RakeTask.
47 48 49 |
# File 'app/models/rake_ui/rake_task.rb', line 47 def initialize(task) @task = task end |
Instance Attribute Details
#task ⇒ Object (readonly)
Returns the value of attribute task.
44 45 46 |
# File 'app/models/rake_ui/rake_task.rb', line 44 def task @task end |
Class Method Details
.all ⇒ Object
23 24 25 26 27 |
# File 'app/models/rake_ui/rake_task.rb', line 23 def self.all self.load.map do |task| new(task) end end |
.find_by_id(id) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/rake_ui/rake_task.rb', line 35 def self.find_by_id(id) t = all i = from_safe_identifier(id) t.find do |task| task.name == i end end |
.from_safe_identifier(id) ⇒ Object
9 10 11 |
# File 'app/models/rake_ui/rake_task.rb', line 9 def self.from_safe_identifier(id) CGI.unescape(id) end |
.internal ⇒ Object
29 30 31 32 33 |
# File 'app/models/rake_ui/rake_task.rb', line 29 def self.internal self.load.map { |task| new(task) }.select(&:is_internal_task) end |
.load ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/models/rake_ui/rake_task.rb', line 13 def self.load # Enables 'desc' to show up as full_comments if Rake::TaskManager.respond_to? :record_task_metadata Rake::TaskManager. = true end Rails.application.load_tasks Rake::Task.tasks end |
.to_safe_identifier(id) ⇒ Object
5 6 7 |
# File 'app/models/rake_ui/rake_task.rb', line 5 def self.to_safe_identifier(id) CGI.escape(id) end |
Instance Method Details
#build_rake_command(args: nil, environment: nil) ⇒ Object
returns an invokable rake command FOO=bar rake create_something rake create_something rake create_something
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/rake_ui/rake_task.rb', line 110 def build_rake_command(args: nil, environment: nil) command = "" if environment command += "#{environment} " end command += "rake #{name}" if args command += "[#{args}]" end command end |
#call(args: nil, environment: nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/rake_ui/rake_task.rb', line 83 def call(args: nil, environment: nil) rake_command = build_rake_command(args: args, environment: environment) rake_task_log = RakeUi::RakeTaskLog.build_new_for_command( name: name, args: args, environment: environment, rake_command: rake_command, rake_definition_file: rake_definition_file, raker_id: id ) puts "[rake_ui] [rake_task] [forked] #{rake_task_log.rake_command_with_logging}" fork do system(rake_task_log.rake_command_with_logging) system(rake_task_log.command_to_mark_log_finished) end rake_task_log end |
#id ⇒ Object
51 52 53 |
# File 'app/models/rake_ui/rake_task.rb', line 51 def id RakeUi::RakeTask.to_safe_identifier(name) end |
#internal_task? ⇒ Boolean
thinking this is the sanest way to discern application vs gem defined tasks (like rails, devise etc)
73 74 75 76 77 78 79 80 81 |
# File 'app/models/rake_ui/rake_task.rb', line 73 def internal_task? actions.any? { |a| !a.to_s.include? "/ruby/gems" } # this was my initial thought here, leaving for posterity in case we need to or the definition of custom # from initial investigation the actions seemed like the most consistent as locations is sometimes empty # locations.any? do |location| # !location.match(/\/bundle\/gems/) # end end |
#is_internal_task ⇒ Object
68 69 70 |
# File 'app/models/rake_ui/rake_task.rb', line 68 def is_internal_task internal_task? end |
#rake_definition_file ⇒ Object
actions will be something like #<Proc:0x000055a2737fe778@/some/rails/app/lib/tasks/auto_annotate_models.rake:4>
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/rake_ui/rake_task.rb', line 56 def rake_definition_file definition = actions.first || "" if definition.respond_to?(:source_location) definition.source_location.join(":") else definition end rescue "unable_to_determine_defining_file" end |