jobler 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3623c18e11b1420eb4930ddd2f899e42d814c6c5
4
- data.tar.gz: fa3ddd60982e1d53745983cce238b4960c49fcba
3
+ metadata.gz: 48611c7dac3539e71c56fd8b94861495e6d42bfd
4
+ data.tar.gz: 90ace36fd054d1eb70b55947ace2d5c83a5be55d
5
5
  SHA512:
6
- metadata.gz: ed1449d9d221793711b4e65f8d2d875b2f554974aeccc8d464e5184852a65a0a6a2149e4f6665d5704c22ce97b026f02c8756846c0c031e8304fdf052336f848
7
- data.tar.gz: 50e7709172176db511bf87badb9973e0c966560516a52183324eec3441df1cb84331999ebe8d31ea7dc3e3154686e0f87fc764fb02d4522b823716161abec162
6
+ metadata.gz: 9d5a976300160f6a0144fd7c5225c0d187023d5b1f259db31bdd385419547fcf7c38fc7e0ed212af39fd41086c05f9eb628aaffb97e76aa7fa05257d2644227c
7
+ data.tar.gz: 5620d5fede8a100fa849d98c32df9001573b9aa1c2fb9c5dfc85f481640a6e02cafbf12034aab837f992adaf2ae41e1c2101b1901c3bbc523eeda6eab5ff0acd
data/README.md CHANGED
@@ -36,6 +36,7 @@ end
36
36
 
37
37
  Jobler is going to queue its jobs through the ActiveJob queue called `:jobler`, so make sure a worker is listening to that queue.
38
38
 
39
+
39
40
  ## Usage
40
41
 
41
42
  Write a new Jobler located in "app/joblers":
@@ -77,6 +78,31 @@ end
77
78
 
78
79
  This will show a wait page and them a complete page with a download link, once the job is completed.
79
80
 
81
+
82
+ # Rendering views
83
+
84
+ First add a special controller that your Jobler's can use:
85
+
86
+ ```ruby
87
+ class ApplicationJoblerController < ApplicationController
88
+ end
89
+ ```
90
+
91
+ Then call render from within the execute method:
92
+ ```ruby
93
+ class TestRenderJobler < Jobler::BaseJobler
94
+ def execute!
95
+ create_result!(
96
+ name: "render",
97
+ content: render(:show)
98
+ )
99
+ end
100
+ end
101
+ ```
102
+
103
+ This will render the view located at "app/joblers/test_render_jobler/show.*"
104
+
105
+
80
106
  ## License
81
107
 
82
108
  This project rocks and uses MIT-LICENSE.
@@ -2,12 +2,17 @@ class Jobler::BaseJobler
2
2
  attr_reader :args, :job
3
3
 
4
4
  def create_result!(args)
5
- temp_file = args.fetch(:temp_file)
6
- temp_file.close unless temp_file.closed?
5
+ if args[:temp_file]
6
+ temp_file = args.fetch(:temp_file)
7
+ temp_file.close unless temp_file.closed?
8
+ content = File.read(temp_file.path)
9
+ else
10
+ content = args.fetch(:content)
11
+ end
7
12
 
8
13
  job.results.create!(
9
14
  name: args.fetch(:name),
10
- result: File.read(temp_file.path)
15
+ result: content
11
16
  )
12
17
  end
13
18
 
@@ -15,6 +20,18 @@ class Jobler::BaseJobler
15
20
  raise NoMethodError, "You should define the 'execute!' method on #{self.class.name}"
16
21
  end
17
22
 
23
+ def jobler_name
24
+ new_name = ""
25
+
26
+ parts = self.class.name.split("::")
27
+ parts.each do |part|
28
+ new_name << "/" unless new_name.empty?
29
+ new_name << part.underscore
30
+ end
31
+
32
+ new_name
33
+ end
34
+
18
35
  def increment_progress!
19
36
  @_progress_count ||= 0.0
20
37
  @_progress_count += 1.0
@@ -38,6 +55,19 @@ class Jobler::BaseJobler
38
55
  @_progress_total = new_total.to_f
39
56
  end
40
57
 
58
+ def render(template_path, locals = {})
59
+ if template_path.is_a?(Symbol)
60
+ template_path = "joblers/#{jobler_name}/#{template_path}"
61
+ end
62
+
63
+ controller = ::ApplicationJoblerController.new
64
+ controller.instance_variable_set(:@jobler, self)
65
+ controller.response = ActionDispatch::Response.new
66
+
67
+ render_result = controller.render(template_path, formats: Mime::EXTENSION_LOOKUP.keys, layout: false, locals: {jobler: self}.merge(locals))
68
+ render_result.join
69
+ end
70
+
41
71
  def result
42
72
  raise NoMethodError, "You should define the 'result' method on #{self.class.name}"
43
73
  end
@@ -1,3 +1,3 @@
1
1
  module Jobler
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj