Class: Fcid::Publisher::Base
- Inherits:
-
Object
- Object
- Fcid::Publisher::Base
- Includes:
- ActionController::Layout, ActionController::UrlWriter, ActionMailer::AdvAttrAccessor, ActionMailer::Helpers, ActionView::Helpers
- Defined in:
- lib/fcid/publisher/base.rb
Defined Under Namespace
Classes: Controller
Constant Summary collapse
- @@raise_delivery_errors =
true
- @@perform_deliveries =
true
- @@deliveries =
[]
- @@default_charset =
"utf-8"
- @@protected_instance_variables =
%w(@body)
Class Attribute Summary collapse
- .publisher_name ⇒ Object (also: controller_name, controller_path)
Instance Attribute Summary collapse
-
#action_name ⇒ Object
readonly
Returns the value of attribute action_name.
-
#default_template_name ⇒ Object
readonly
Returns the value of attribute default_template_name.
-
#feed ⇒ Object
readonly
The mail object instance referenced by this publisher.
-
#template_name ⇒ Object
readonly
Returns the value of attribute template_name.
Class Method Summary collapse
- .deliver(feed) ⇒ Object
-
.method_missing(method_symbol, *parameters) ⇒ Object
:nodoc:.
- .register(name) ⇒ Object
- .register_all ⇒ Object
-
.respond_to?(method_symbol, include_private = false) ⇒ Boolean
:nodoc:.
- .template_root ⇒ Object
- .template_root=(root) ⇒ Object
Instance Method Summary collapse
-
#create!(method_name, *parameters) ⇒ Object
:nodoc:.
- #deliver!(feed = @feed) ⇒ Object
- #images(src, url = nil) ⇒ Object
-
#initialize(method_name = nil, *parameters) ⇒ Base
constructor
Instantiate a new publisher object.
-
#publisher_name(value = nil) ⇒ Object
Override the publisher name, which defaults to an inflected version of the publisher’s class name.
- #publisher_name=(value) ⇒ Object
Constructor Details
#initialize(method_name = nil, *parameters) ⇒ Base
Instantiate a new publisher object. If method_name
is not nil
, the publisher will be initialized according to the named method. If not, the publisher will remain uninitialized (useful when you only need to invoke the “receive” method, for instance).
194 195 196 197 |
# File 'lib/fcid/publisher/base.rb', line 194 def initialize(method_name=nil, *parameters) #:nodoc: @controller = Controller.new create!(method_name, *parameters) if method_name end |
Class Attribute Details
.publisher_name ⇒ Object Also known as: controller_name, controller_path
121 122 123 |
# File 'lib/fcid/publisher/base.rb', line 121 def publisher_name @publisher_name ||= name.underscore end |
Instance Attribute Details
#action_name ⇒ Object (readonly)
Returns the value of attribute action_name.
116 117 118 |
# File 'lib/fcid/publisher/base.rb', line 116 def action_name @action_name end |
#default_template_name ⇒ Object (readonly)
Returns the value of attribute default_template_name.
116 117 118 |
# File 'lib/fcid/publisher/base.rb', line 116 def default_template_name @default_template_name end |
#feed ⇒ Object (readonly)
The mail object instance referenced by this publisher.
115 116 117 |
# File 'lib/fcid/publisher/base.rb', line 115 def feed @feed end |
#template_name ⇒ Object (readonly)
Returns the value of attribute template_name.
116 117 118 |
# File 'lib/fcid/publisher/base.rb', line 116 def template_name @template_name end |
Class Method Details
.deliver(feed) ⇒ Object
169 170 171 |
# File 'lib/fcid/publisher/base.rb', line 169 def deliver(feed) new.deliver!(feed) end |
.method_missing(method_symbol, *parameters) ⇒ Object
:nodoc:
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/fcid/publisher/base.rb', line 133 def method_missing(method_symbol, *parameters) #:nodoc: match = matches_dynamic_method?(method_symbol) case match[1] when 'create' then new(match[2], *parameters).feed when 'deliver' then new(match[2], *parameters).deliver! when 'register' then new(match[2], *parameters).register! when 'new' then nil else super end end |
.register(name) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/fcid/publisher/base.rb', line 146 def register(name) logger.debug "registering template: #{name}" if logger content = new.send(name + "_template") oneline = story = "" case content when String oneline = content when Array oneline,story = content.first,content.last when Hash oneline = content[:oneline] stroy = content[:story] end ActivityTemplate.register("#{self.name}.#{name}",oneline,story) end |
.register_all ⇒ Object
162 163 164 165 166 167 |
# File 'lib/fcid/publisher/base.rb', line 162 def register_all publisher_instance_methods = self.public_instance_methods - UC::Publisher::Base.public_instance_methods publisher_instance_methods.grep(/_action$/).each do |action| register(action) end end |
.respond_to?(method_symbol, include_private = false) ⇒ Boolean
:nodoc:
129 130 131 |
# File 'lib/fcid/publisher/base.rb', line 129 def respond_to?(method_symbol, include_private = false) #:nodoc: matches_dynamic_method?(method_symbol) || super end |
.template_root ⇒ Object
173 174 175 |
# File 'lib/fcid/publisher/base.rb', line 173 def template_root self.view_paths && self.view_paths.first end |
Instance Method Details
#create!(method_name, *parameters) ⇒ Object
:nodoc:
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/fcid/publisher/base.rb', line 204 def create!(method_name, *parameters) #:nodoc: initialize_defaults(method_name) __send__(method_name, *parameters) delivery_method case method_name when /_action$/,/_feed$/ :action when /_notification$/ :notification when /_email$/ :email when /_activity$/ :activity when /_popup$/ :popup else raise "unknow delivery method" end if delivery_method.nil? # notification will be sent delivery_method :test if Rails.env == "test" && delivery_method != :notification # If an explicit, textual body has not been set, we check assumptions. unless String === @body_template template_exists ||= template_root["#{publisher_name}/#{@template}"] @body_template = (@template, @body_data.merge(@body)) if template_exists end # build the feed object itself @feed = create_feed end |
#deliver!(feed = @feed) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/fcid/publisher/base.rb', line 236 def deliver!(feed = @feed) raise "no feed object available for delivery!" unless feed unless logger.nil? logger.info "Sent feed to #{Array(recipients).join(', ')}" logger.debug "\n#{feed.inspect}" end begin m = "perform_delivery_#{delivery_method}" # raise m __send__(m, feed) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors raise e if raise_delivery_errors end end |
#images(src, url = nil) ⇒ Object
199 200 201 |
# File 'lib/fcid/publisher/base.rb', line 199 def images(src,url=nil) @images << [src,url] end |
#publisher_name(value = nil) ⇒ Object
Override the publisher name, which defaults to an inflected version of the publisher’s class name. If you want to use a template in a non-standard location, you can use this to specify that location.
102 103 104 105 106 107 108 |
# File 'lib/fcid/publisher/base.rb', line 102 def publisher_name(value = nil) if value self.publisher_name = value else self.class.publisher_name end end |
#publisher_name=(value) ⇒ Object
110 111 112 |
# File 'lib/fcid/publisher/base.rb', line 110 def publisher_name=(value) self.class.publisher_name = value end |