lipsiadmin 5.1.6 → 5.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/lib/access_control/authentication.rb +20 -20
  2. data/lib/access_control/base.rb +40 -40
  3. data/lib/controller/ext.rb +27 -27
  4. data/lib/controller/lipsiadmin_controller.rb +3 -3
  5. data/lib/controller/pdf_builder.rb +33 -31
  6. data/lib/controller/rescue.rb +12 -12
  7. data/lib/controller/responds_to_parent.rb +5 -5
  8. data/lib/data_base/attachment.rb +60 -60
  9. data/lib/data_base/attachment/attach.rb +18 -18
  10. data/lib/data_base/attachment/geometry.rb +7 -7
  11. data/lib/data_base/attachment/iostream.rb +1 -1
  12. data/lib/data_base/attachment/processor.rb +2 -2
  13. data/lib/data_base/attachment/storage.rb +11 -11
  14. data/lib/data_base/attachment/thumbnail.rb +2 -2
  15. data/lib/data_base/attachment_table.rb +27 -27
  16. data/lib/data_base/translate_attributes.rb +9 -9
  17. data/lib/data_base/utility_scopes.rb +7 -7
  18. data/lib/data_base/without_table.rb +10 -10
  19. data/lib/generator.rb +4 -4
  20. data/lib/loops.rb +77 -77
  21. data/lib/loops/base.rb +2 -2
  22. data/lib/loops/daemonize.rb +5 -5
  23. data/lib/loops/process_manager.rb +3 -3
  24. data/lib/loops/worker.rb +1 -1
  25. data/lib/loops/worker_pool.rb +1 -1
  26. data/lib/mailer/exception_notifier.rb +5 -5
  27. data/lib/mailer/pdf_builder.rb +20 -18
  28. data/lib/utils/literal.rb +6 -6
  29. data/lib/utils/pdf_builder.rb +10 -10
  30. data/lib/version.rb +1 -1
  31. data/lib/view/helpers/backend_helper.rb +123 -123
  32. data/lib/view/helpers/ext/button.rb +7 -7
  33. data/lib/view/helpers/ext/column_model.rb +18 -18
  34. data/lib/view/helpers/ext/component.rb +50 -50
  35. data/lib/view/helpers/ext/configuration.rb +5 -5
  36. data/lib/view/helpers/ext/grid.rb +46 -46
  37. data/lib/view/helpers/ext/store.rb +14 -14
  38. data/lib/view/helpers/ext/tool_bar.rb +6 -6
  39. data/lib/view/helpers/ext_helper.rb +21 -21
  40. data/lib/view/helpers/frontend_helper.rb +5 -5
  41. data/lib/view/helpers/pdf_helper.rb +7 -7
  42. data/lib/view/helpers/view_helper.rb +28 -28
  43. data/lipsiadmin_generators/attachment/attachment_generator.rb +7 -7
  44. data/lipsiadmin_generators/attachment/templates/controller.rb +13 -13
  45. data/lipsiadmin_generators/attachment/templates/migration.rb +1 -1
  46. data/lipsiadmin_generators/backend/backend_generator.rb +9 -9
  47. data/lipsiadmin_generators/backend/templates/controllers/backend/accounts_controller.rb +10 -10
  48. data/lipsiadmin_generators/backend/templates/controllers/backend/sessions_controller.rb +2 -2
  49. data/lipsiadmin_generators/backend/templates/controllers/javascripts_controller.rb +2 -2
  50. data/lipsiadmin_generators/backend/templates/migrations/create_accounts.rb +5 -5
  51. data/lipsiadmin_generators/backend/templates/models/account.rb +16 -16
  52. data/lipsiadmin_generators/backend/templates/models/account_access.rb +11 -11
  53. data/lipsiadmin_generators/backend/templates/models/notifier.rb +2 -2
  54. data/lipsiadmin_generators/backend_page/backend_page_generator.rb +22 -22
  55. data/lipsiadmin_generators/backend_page/templates/controller.rb +9 -9
  56. data/lipsiadmin_generators/backend_page/templates/functional_test.rb +10 -10
  57. data/lipsiadmin_generators/frontend/frontend_generator.rb +5 -5
  58. data/lipsiadmin_generators/frontend/templates/controllers/frontend/sessions_controller.rb +3 -3
  59. data/lipsiadmin_generators/loops/loops_generator.rb +2 -2
  60. data/lipsiadmin_generators/pdf/pdf_generator.rb +7 -7
  61. data/lipsiadmin_generators/state_session/state_session_generator.rb +9 -9
  62. data/lipsiadmin_generators/state_session/templates/controller.rb +2 -2
  63. data/lipsiadmin_generators/state_session/templates/migration.rb +2 -2
  64. data/resources/rdoc/horo.rb +3 -3
  65. metadata +4 -4
@@ -2,30 +2,30 @@ module Lipsiadmin
2
2
  module DataBase
3
3
  # This class create a *fake* table that can be usefull if you need for example
4
4
  # perform validations. Take a look to this test case:
5
- #
5
+ #
6
6
  # Examples:
7
- #
7
+ #
8
8
  # class Contact < Lipsiadmin::DataBase::WithoutTable
9
9
  # column :name, :string
10
10
  # column :company, :string
11
11
  # column :telephone, :string
12
12
  # column :email, :string
13
13
  # column :message, :text
14
- #
14
+ #
15
15
  # validates_presence_of :name, :message
16
16
  # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
17
17
  # end
18
- #
18
+ #
19
19
  # Now we need to validate a contact, and if the validations is okey send an email or if not raise errors
20
- #
20
+ #
21
21
  # @contact = Contact.new(params[:contact])
22
- # if @contact.valid?
22
+ # if @contact.valid?
23
23
  # Notifier.deliver_support_request(@contact)
24
24
  # else
25
25
  # flash[:notice] = "There are some problems"
26
26
  # render :action => :support_request
27
27
  # end
28
- #
28
+ #
29
29
  class WithoutTable < ActiveRecord::Base
30
30
  self.abstract_class = true
31
31
 
@@ -38,13 +38,13 @@ module Lipsiadmin
38
38
  def columns()
39
39
  @columns ||= []
40
40
  end
41
-
41
+
42
42
  # Define columns for a this *fake* table
43
43
  def column(name, sql_type = nil, default = nil, null = true)
44
44
  columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
45
45
  reset_column_information
46
46
  end
47
-
47
+
48
48
  # Resets all the cached information about columns, which will cause them to be reloaded on the next request.
49
49
  def reset_column_information
50
50
  generated_methods.each { |name| undef_method(name) }
@@ -53,4 +53,4 @@ module Lipsiadmin
53
53
  end
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -11,7 +11,7 @@ module Lipsiadmin#:nodoc:
11
11
  alias_method_chain :use_component_sources!, :lipsiadmin
12
12
  end
13
13
  end
14
-
14
+
15
15
  # Append my sources
16
16
  def use_component_sources_with_lipsiadmin!
17
17
  use_component_sources_without_lipsiadmin!
@@ -38,7 +38,7 @@ module Lipsiadmin#:nodoc:
38
38
  "public/images/",
39
39
  "public/javascripts/",
40
40
  "public/stylesheet/"]
41
-
41
+
42
42
  def with_source_in(path)
43
43
  root = source_path(path)
44
44
  Find.find(root) do |f|
@@ -63,7 +63,7 @@ module Lipsiadmin#:nodoc:
63
63
  # Need to do this for remove all directories
64
64
  directories.each { |d| directory(d) unless PROTECTED_DIRS.include?(d) }
65
65
  end
66
-
66
+
67
67
  private
68
68
  def render_template_part(template_options)
69
69
  # Getting Sandbox to evaluate part template in it
@@ -89,7 +89,7 @@ module Lipsiadmin#:nodoc:
89
89
  end
90
90
  end
91
91
  end # Module Create
92
-
92
+
93
93
  module Create#:nodoc:
94
94
  include Base
95
95
 
@@ -1,54 +1,54 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Lipsiadmin
4
-
4
+
5
5
  # ==Simple background loops framework for rails
6
- #
7
- # Loops is a small and lightweight framework for Ruby on Rails created to support simple
8
- # background loops in your application which are usually used to do some background data processing
6
+ #
7
+ # Loops is a small and lightweight framework for Ruby on Rails created to support simple
8
+ # background loops in your application which are usually used to do some background data processing
9
9
  # on your servers (queue workers, batch tasks processors, etc).
10
- #
10
+ #
11
11
  # Authors:: Alexey Kovyrin and Dmytro Shteflyuk
12
12
  # Comments:: This plugin has been created in Scribd.com for internal use.
13
- #
13
+ #
14
14
  # == What tasks could you use it for?
15
- #
16
- # Originally loops plugin was created to make our own loops code more organized. We used to have tens
17
- # of different modules with methods that were called with script/runner and then used with nohup and
18
- # other not so convenient backgrounding techniques. When you have such a number of loops/workers to
19
- # run in background it becomes a nightmare to manage them on a regular basis (restarts, code upgrades,
15
+ #
16
+ # Originally loops plugin was created to make our own loops code more organized. We used to have tens
17
+ # of different modules with methods that were called with script/runner and then used with nohup and
18
+ # other not so convenient backgrounding techniques. When you have such a number of loops/workers to
19
+ # run in background it becomes a nightmare to manage them on a regular basis (restarts, code upgrades,
20
20
  # status/health checking, etc).
21
- #
22
- # After a short time of writing our loops in more organized ways we were able to generalize most of the
23
- # loops code so now our loops look like a classes with a single mandatory public method called *run*.
24
- # Everything else (spawning many workers, managing them, logging, backgrounding, pid-files management,
21
+ #
22
+ # After a short time of writing our loops in more organized ways we were able to generalize most of the
23
+ # loops code so now our loops look like a classes with a single mandatory public method called *run*.
24
+ # Everything else (spawning many workers, managing them, logging, backgrounding, pid-files management,
25
25
  # etc) is handled by the plugin it
26
- #
27
- #
26
+ #
27
+ #
28
28
  # == But there are dozens of libraries like this! Why do we need one more?
29
- #
30
- # The major idea behind this small project was to create a deadly simple and yet robust framework to
31
- # be able to run some tasks in background and do not think about spawning many workers, restarting
32
- # them when they die, etc. So, if you need to be able to run either one or many copies of your worker or
33
- # you do not want to think about re-spawning dead workers and do not want to spend megabytes of RAM on
34
- # separate copies of Ruby interpreter (when you run each copy of your loop as a separate process
29
+ #
30
+ # The major idea behind this small project was to create a deadly simple and yet robust framework to
31
+ # be able to run some tasks in background and do not think about spawning many workers, restarting
32
+ # them when they die, etc. So, if you need to be able to run either one or many copies of your worker or
33
+ # you do not want to think about re-spawning dead workers and do not want to spend megabytes of RAM on
34
+ # separate copies of Ruby interpreter (when you run each copy of your loop as a separate process
35
35
  # controlled by monit/god/etc), then I'd recommend you to try this framework -- you'd like it.
36
- #
37
- #
36
+ #
37
+ #
38
38
  # == How to use?
39
- #
40
- # Generate binary and configuration files by running
41
- #
42
- # script/generate loops
43
- #
39
+ #
40
+ # Generate binary and configuration files by running
41
+ #
42
+ # script/generate loops
43
+ #
44
44
  # This will create the following list of files:
45
- #
45
+ #
46
46
  # script/loops # binary file that will be used to manage your loops
47
47
  # config/loops.yml # example configuration file
48
48
  # app/loops/simple.rb # REALLY simple loop example
49
- #
49
+ #
50
50
  # Here is a simple loop scaffold for you to start from (put this file to app/loops/hello_world_loop.rb):
51
- #
51
+ #
52
52
  # class HelloWorldLoop < Lipsiadmin::Loops::Base
53
53
  # def run
54
54
  # debug("Hello, debug log!")
@@ -56,73 +56,73 @@ module Lipsiadmin
56
56
  # debug("Hello, debug log (yes, once again)!")
57
57
  # end
58
58
  # end
59
- #
60
- # When you have your loop ready to use, add the following lines to your (maybe empty yet) config/loops.yml
59
+ #
60
+ # When you have your loop ready to use, add the following lines to your (maybe empty yet) config/loops.yml
61
61
  # file:
62
- #
62
+ #
63
63
  # hello_world:
64
64
  # sleep_period: 10
65
- #
65
+ #
66
66
  # This is it! To start your loop, just run one of the following commands:
67
- #
67
+ #
68
68
  # # Generates: list all configured loops:
69
69
  # $ script/loops -L
70
- #
70
+ #
71
71
  # # Generates: run all enabled (actually non-disabled) loops in foreground:
72
72
  # $ script/loops -a
73
- #
73
+ #
74
74
  # # Generates: run all enabled loops in background:
75
75
  # $ script/loops -d -a
76
- #
76
+ #
77
77
  # # Generates: run specific loop in background:
78
78
  # $ ./script/loops -d -l hello_world
79
- #
79
+ #
80
80
  # # Generates: all possible options:
81
81
  # $ ./script/loops -h
82
- #
83
- #
82
+ #
83
+ #
84
84
  # == How to run more than one worker?
85
- #
86
- # If you want to have more than one copy of your worker running, that is as simple as adding one
85
+ #
86
+ # If you want to have more than one copy of your worker running, that is as simple as adding one
87
87
  # option to your loop configuration:
88
- #
88
+ #
89
89
  # hello_world:
90
90
  # sleep_period: 10
91
- # workers_number: 1
92
- #
93
- # This _workers_number_ option would say loops manager to spawn more than one copy of your loop
94
- # and run them in parallel. The only thing you'd need to do is to think about concurrent work of
95
- # your loops. For example, if you have some kind of database table with elements you need to
91
+ # workers_number: 1
92
+ #
93
+ # This _workers_number_ option would say loops manager to spawn more than one copy of your loop
94
+ # and run them in parallel. The only thing you'd need to do is to think about concurrent work of
95
+ # your loops. For example, if you have some kind of database table with elements you need to
96
96
  # process, you can create a simple database-based locks system or use any memcache-based locks.
97
- #
98
- #
97
+ #
98
+ #
99
99
  # == There is this <tt>workers_engine</tt> option in config file. What it could be used for?
100
- #
101
- # There are two so called "workers engines" in this plugin: <tt>fork</tt> and <tt>thread</tt>. They're used
102
- # to control the way process manager would spawn new loops workers: with <tt>fork</tt> engine we'll
103
- # load all loops classes and then fork ruby interpreter as many times as many workers we need.
104
- # With <tt>thread</tt> engine we'd do Thread.new instead of forks. Thread engine could be useful if you
105
- # are sure your loop won't lock ruby interpreter (it does not do native calls, etc) or if you
100
+ #
101
+ # There are two so called "workers engines" in this plugin: <tt>fork</tt> and <tt>thread</tt>. They're used
102
+ # to control the way process manager would spawn new loops workers: with <tt>fork</tt> engine we'll
103
+ # load all loops classes and then fork ruby interpreter as many times as many workers we need.
104
+ # With <tt>thread</tt> engine we'd do Thread.new instead of forks. Thread engine could be useful if you
105
+ # are sure your loop won't lock ruby interpreter (it does not do native calls, etc) or if you
106
106
  # use some interpreter that does not support forks (like jruby).
107
- #
107
+ #
108
108
  # Default engine is <tt>fork</tt>.
109
- #
110
- #
109
+ #
110
+ #
111
111
  # == What Ruby implementations does it work for?
112
- #
113
- # We've tested and used the plugin on MRI 1.8.6 and on JRuby 1.1.5. At this point we do not support
114
- # demonization in JRuby and never tested the code on Ruby 1.9. Obviously because of JVM limitations
112
+ #
113
+ # We've tested and used the plugin on MRI 1.8.6 and on JRuby 1.1.5. At this point we do not support
114
+ # demonization in JRuby and never tested the code on Ruby 1.9. Obviously because of JVM limitations
115
115
  # you won't be able to use +fork+ workers engine in JRuby, but threaded workers do pretty well.
116
116
  #
117
117
  module Loops
118
-
118
+
119
119
  class << self
120
-
120
+
121
121
  # Set/Return the main config
122
122
  def config
123
123
  @@config
124
124
  end
125
-
125
+
126
126
  # Set/Return the loops config
127
127
  def loops_config
128
128
  @@loops_config
@@ -132,7 +132,7 @@ module Lipsiadmin
132
132
  def global_config
133
133
  @@global_config
134
134
  end
135
-
135
+
136
136
  # Load the yml config file, default config/loops.yml
137
137
  def load_config(file)
138
138
  @@config = YAML.load_file(file)
@@ -141,7 +141,7 @@ module Lipsiadmin
141
141
 
142
142
  @@logger = create_logger('global', global_config)
143
143
  end
144
-
144
+
145
145
  # Start loops, default :all
146
146
  def start_loops!(loops_to_start = :all)
147
147
  @@running_loops = []
@@ -154,7 +154,7 @@ module Lipsiadmin
154
154
  klass = load_loop_class(name)
155
155
  next unless klass
156
156
 
157
- start_loop(name, klass, config)
157
+ start_loop(name, klass, config)
158
158
  @@running_loops << name
159
159
  end
160
160
 
@@ -184,7 +184,7 @@ module Lipsiadmin
184
184
 
185
185
  def load_loop_class(name)
186
186
  begin
187
- klass_file = LOOPS_ROOT + "/app/loops/#{name}.rb"
187
+ klass_file = LOOPS_ROOT + "/app/loops/#{name}.rb"
188
188
  debug "Loading class file: #{klass_file}"
189
189
  require(klass_file)
190
190
  rescue Exception
@@ -253,12 +253,12 @@ module Lipsiadmin
253
253
  @@pm.stop_workers!
254
254
  }
255
255
 
256
- trap('INT') {
256
+ trap('INT') {
257
257
  warn "Received an INT signal... stopping..."
258
258
  @@pm.stop_workers!
259
259
  }
260
260
 
261
- trap('EXIT') {
261
+ trap('EXIT') {
262
262
  warn "Received a EXIT 'signal'... stopping..."
263
263
  @@pm.stop_workers!
264
264
  }
@@ -268,10 +268,10 @@ module Lipsiadmin
268
268
  ActiveRecord::Base.clear_active_connections!
269
269
  ActiveRecord::Base.verify_active_connections!
270
270
  end
271
-
271
+
272
272
  end
273
273
  end
274
274
  end
275
275
 
276
276
  require 'loops/process_manager'
277
- require 'loops/base'
277
+ require 'loops/base'
@@ -12,7 +12,7 @@ module Lipsiadmin
12
12
  #
13
13
  class Base#:nodoc:
14
14
  attr_accessor :name, :config, :logger
15
-
15
+
16
16
  # The initialize method, default we pass the logger
17
17
  def initialize(logger)
18
18
  self.logger = logger
@@ -49,4 +49,4 @@ module Lipsiadmin
49
49
  end
50
50
  end
51
51
  end
52
- end
52
+ end
@@ -2,8 +2,8 @@ module Lipsiadmin
2
2
  module Loops
3
3
  module Daemonize#:nodoc:
4
4
  def self.read_pid(pid_file)
5
- File.open(pid_file) do |f|
6
- f.gets.to_i
5
+ File.open(pid_file) do |f|
6
+ f.gets.to_i
7
7
  end
8
8
  rescue Errno::ENOENT
9
9
  0
@@ -15,7 +15,7 @@ module Lipsiadmin
15
15
  if defined?(::JRuby)
16
16
  system "kill -0 #{pid} &> /dev/null"
17
17
  return $? == 0
18
- else
18
+ else
19
19
  Process.kill(0, pid)
20
20
  end
21
21
  true
@@ -66,7 +66,7 @@ module Lipsiadmin
66
66
  File.umask(0000) # Insure sensible umask
67
67
 
68
68
  return sess_id
69
- end
69
+ end
70
70
  end
71
71
  end
72
- end
72
+ end
@@ -38,7 +38,7 @@ module Lipsiadmin
38
38
 
39
39
  break if @shutdown
40
40
  logger.debug("Sleeping for #{@config['poll_period']} seconds...")
41
- sleep(@config['poll_period'])
41
+ sleep(@config['poll_period'])
42
42
  end
43
43
  ensure
44
44
  unless wait_for_workers(10)
@@ -70,7 +70,7 @@ module Lipsiadmin
70
70
 
71
71
  logger.debug("#{running_total} workers are still running! Sleeping for a second...")
72
72
  sleep(1)
73
- end
73
+ end
74
74
 
75
75
  return false
76
76
  end
@@ -98,4 +98,4 @@ module Lipsiadmin
98
98
  end
99
99
  end
100
100
  end
101
- end
101
+ end
@@ -10,7 +10,7 @@ module Lipsiadmin
10
10
 
11
11
  @name = name
12
12
  @logger = logger
13
- @engine = engine
13
+ @engine = engine
14
14
  @worker_block = blk
15
15
 
16
16
  @shutdown = false
@@ -15,7 +15,7 @@ module Lipsiadmin
15
15
 
16
16
  def start_workers(number)
17
17
  logger.debug("Creating #{number} workers for #{name} loop...")
18
- number.times do
18
+ number.times do
19
19
  @workers << Lipsiadmin::Loops::Worker.new(name, logger, @engine, &@worker_block)
20
20
  end
21
21
  end
@@ -18,14 +18,14 @@ module Lipsiadmin
18
18
 
19
19
  @@email_prefix = "[ERROR] "
20
20
  cattr_accessor :email_prefix
21
-
21
+
22
22
  self.mailer_name = "exception"
23
23
  self.template_root = "#{File.dirname(__FILE__)}"
24
24
 
25
25
  def self.reloadable?#:nodoc:
26
- false
26
+ false
27
27
  end
28
-
28
+
29
29
  # This method deliver the exception for the given controller and request
30
30
  def exception(exception, controller, request)
31
31
  content_type "text/plain"
@@ -41,6 +41,6 @@ module Lipsiadmin
41
41
  end
42
42
 
43
43
  end
44
-
44
+
45
45
  end
46
- end
46
+ end