Class: Facebooker::Rails::Publisher::FacebookTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Facebooker::Rails::Publisher::FacebookTemplate
- Defined in:
- lib/facebooker/rails/publisher.rb
Class Method Summary collapse
- .bundle_id_for_class_and_method(klass, method) ⇒ Object
- .cache(klass, method, template) ⇒ Object
- .clear_cache! ⇒ Object
- .find_cached(klass, method) ⇒ Object
- .find_in_db(klass, method) ⇒ Object
- .for_class_and_method(klass, method) ⇒ Object
- .hashed_content(klass, method) ⇒ Object
- .inspect(*args) ⇒ Object
- .register(klass, method) ⇒ Object
- .setup_publisher(klass, method) ⇒ Object
- .template_name(klass, method) ⇒ Object
Instance Method Summary collapse
Class Method Details
.bundle_id_for_class_and_method(klass, method) ⇒ Object
133 134 135 |
# File 'lib/facebooker/rails/publisher.rb', line 133 def bundle_id_for_class_and_method(klass,method) for_class_and_method(klass,method).bundle_id end |
.cache(klass, method, template) ⇒ Object
137 138 139 |
# File 'lib/facebooker/rails/publisher.rb', line 137 def cache(klass,method,template) template_cache[template_name(klass,method)] = template end |
.clear_cache! ⇒ Object
141 142 143 |
# File 'lib/facebooker/rails/publisher.rb', line 141 def clear_cache! self.template_cache = {} end |
.find_cached(klass, method) ⇒ Object
145 146 147 |
# File 'lib/facebooker/rails/publisher.rb', line 145 def find_cached(klass,method) template_cache[template_name(klass,method)] || find_in_db(klass,method) end |
.find_in_db(klass, method) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/facebooker/rails/publisher.rb', line 149 def find_in_db(klass,method) template = find_by_template_name(template_name(klass,method)) if template and template.template_changed?(hashed_content(klass,method)) template.destroy template = nil end if template.nil? template = register(klass,method) end template end |
.for_class_and_method(klass, method) ⇒ Object
130 131 132 |
# File 'lib/facebooker/rails/publisher.rb', line 130 def for_class_and_method(klass,method) find_cached(klass,method) end |
.hashed_content(klass, method) ⇒ Object
168 169 170 171 |
# File 'lib/facebooker/rails/publisher.rb', line 168 def hashed_content(klass, method) publisher = setup_publisher(klass,method) Digest::MD5.hexdigest [publisher.one_line_story_templates, publisher.short_story_templates, publisher.full_story_template].to_json end |
.inspect(*args) ⇒ Object
105 106 107 |
# File 'lib/facebooker/rails/publisher.rb', line 105 def self.inspect(*args) "FacebookTemplate" end |
.register(klass, method) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/facebooker/rails/publisher.rb', line 119 def register(klass,method) publisher = setup_publisher(klass,method) template_id = Facebooker::Session.create.register_template_bundle(publisher.one_line_story_templates,publisher.short_story_templates,publisher.full_story_template,publisher.action_links) template = find_or_initialize_by_template_name(template_name(klass,method)) template.bundle_id = template_id template.content_hash = hashed_content(klass,method) if template.respond_to?(:content_hash) template.save! cache(klass,method,template) template end |
.setup_publisher(klass, method) ⇒ Object
162 163 164 165 166 |
# File 'lib/facebooker/rails/publisher.rb', line 162 def setup_publisher(klass,method) publisher = klass.new publisher.send method + '_template' publisher end |
.template_name(klass, method) ⇒ Object
174 175 176 |
# File 'lib/facebooker/rails/publisher.rb', line 174 def template_name(klass,method) "#{klass.name}::#{method}" end |
Instance Method Details
#template_changed?(hash) ⇒ Boolean
109 110 111 112 113 114 115 |
# File 'lib/facebooker/rails/publisher.rb', line 109 def template_changed?(hash) if respond_to?(:content_hash) content_hash != hash else false end end |