lib/princely.rb in yellowlab-princely-1.2.5.yellowlab.2 vs lib/princely.rb in yellowlab-princely-1.2.5.yellowlab.3
- old
+ new
@@ -19,21 +19,38 @@
require 'princely/rails'
class Princely
VERSION = "1.0.0" unless const_defined?("VERSION")
+ cattr_writer :log_file
attr_accessor :exe_path, :style_sheets, :log_file, :logger
+ def self.prince_executable
+ @@prince_executable ||= begin
+ path = `which prince`.chomp
+ raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
+ path
+ end
+ end
+
+ def self.prince_executable=(path)
+ raise "Configured prince executable '#{path}' is not valid. Check file exists and is executable by user." if File.executable?(path)
+ @@prince_executable = path
+ end
+
+ def self.log_file
+ @@log_file ||= "#{Rails.root}/log/prince.log"
+ end
+
# Initialize method
#
- def initialize()
+ def initialize
# Finds where the application lives, so we can call it.
- @exe_path = `which prince`.chomp
- raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
- @style_sheets = ''
- @log_file = "#{Rails.root}/log/prince.log"
- @logger = Rails.logger
+ @exe_path = self.class.prince_executable
+ @style_sheets = ''
+ @log_file = self.class.log_file
+ @logger = Rails.logger
end
# Sets stylesheets...
# Can pass in multiple paths for css files.
#
@@ -92,6 +109,6 @@
# Actually call the prince command, and pass the entire data stream back.
pdf = IO.popen(path, "w+")
pdf.puts(string)
pdf.close
end
-end
\ No newline at end of file
+end