Class: Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Post
- Extended by:
- FriendlyId
- Defined in:
- app/models/post.rb
Defined Under Namespace
Classes: Translation
Constant Summary collapse
- MetatagNames =
["Title Tag", "Meta Description", "Keywords", "OpenGraph Title", "OpenGraph Description", "OpenGraph Type", "OpenGraph URL", "OpenGraph Image"]
- LiquidParser =
{}
- SortOptions =
["Created_at", "Updated_at", "Random", "Alphabetically"]
- DynamicRedirectOptions =
[[:false,"disabled"],[:latest,"latest subentry"], [:oldest, "eldest subentry"]]
Instance Attribute Summary collapse
-
#hint_label ⇒ Object
Returns the value of attribute hint_label.
Class Method Summary collapse
- .active ⇒ Object
- .load_liquid_methods(options = {}) ⇒ Object
- .post_types_for_search ⇒ Object
- .post_types_for_select ⇒ Object
-
.recreate_cache ⇒ Object
Cache **************************.
Instance Method Summary collapse
- #absolute_public_url ⇒ Object
-
#breadcrumb_name ⇒ Object
Breadcrumb **************************.
- #complete_json ⇒ Object
-
#get_related_object ⇒ Object
Tipos de artigos ************************** Gets the related object by post_type.
-
#kind_of_post_type ⇒ Object
Retorna índice ou mostrar, dependendo do tipo de página.
-
#metatag(name) ⇒ Object
Metatag **************************.
-
#method_missing(meth, *args, &block) ⇒ Object
dynamic methods for post.event or post.consultant .…
- #notification_event_create ⇒ Object
- #notification_event_update ⇒ Object
-
#post_type_for_search ⇒ Object
Retorna os nomes das categorias, independente de pagina de visualização ou de indice.
-
#post_type_form_file ⇒ Object
Exibe Consultor | Filial | etc.
-
#public_url ⇒ Object
URL **************************.
-
#respond_to_all?(method_name) ⇒ Boolean
Instance Methods **************************.
-
#searchable_in_post_type ⇒ Object
Pesquisa ************************** Especifica uma cadeia de texto a ser pesquisado no artigo.
- #set_active_since ⇒ Object
- #set_default_opengraph_values ⇒ Object
- #translations_attributes=(attributes) ⇒ Object
-
#verify_existence_of_opengraph_image ⇒ Object
OpenGraph **************************.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
dynamic methods for post.event or post.consultant .… depending on related object type
112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/post.rb', line 112 def method_missing(meth, *args, &block) if meth.to_s.split(".").first == self..class.name.downcase if meth.to_s.split(".").count == 1 self. else self..send(meth.to_s.split(".").last) end else super end end |
Instance Attribute Details
#hint_label ⇒ Object
Returns the value of attribute hint_label.
22 23 24 |
# File 'app/models/post.rb', line 22 def hint_label @hint_label end |
Class Method Details
.active ⇒ Object
132 133 134 |
# File 'app/models/post.rb', line 132 def self.active Post.where("published = true AND active_since < '#{Time.now.utc}'") end |
.load_liquid_methods(options = {}) ⇒ Object
136 137 138 |
# File 'app/models/post.rb', line 136 def self.load_liquid_methods(={}) end |
.post_types_for_search ⇒ Object
195 196 197 198 199 200 201 202 203 204 |
# File 'app/models/post.rb', line 195 def self.post_types_for_search results = [] path_to_posttypes = File.join(::Rails.root, "app", "views", "posttypes") if Dir.exist?(path_to_posttypes) Dir.foreach(path_to_posttypes) do |name| #.map{|a| File.basename(a, ".html.erb")}.delete_if{|a| a =~ /^_edit/ } results << name.capitalize unless name.include?(".") end end return results end |
.post_types_for_select ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'app/models/post.rb', line 178 def self.post_types_for_select results = [] path_to_posttypes = File.join(::Rails.root, "app", "views", "posttypes") if Dir.exist?(path_to_posttypes) Dir.foreach(path_to_posttypes) do |name| #.map{|a| File.basename(a, ".html.erb")}.delete_if{|a| a =~ /^_edit/ }.delete_if{|a| a[0] == "_"} file_name_path = File.join(path_to_posttypes,name) if File.directory?(file_name_path) Dir.foreach(file_name_path) do |sub_name| file_name = "#{name}#{sub_name}" if File.exist?(File.join(file_name_path,sub_name)) && (sub_name =~ /^_(?!edit).*/) == 0 results << file_name.split(".").first.to_s.titleize if file_name.present? end end end end return results end |
.recreate_cache ⇒ Object
Cache **************************
295 296 297 298 299 300 301 302 303 304 |
# File 'app/models/post.rb', line 295 def self.recreate_cache if RUBY_VERSION.include?("1.9.") PostsCacheWorker.perform_async() else Post.active.each do |post| post.updated_at = Time.now post.save end end end |
Instance Method Details
#absolute_public_url ⇒ Object
222 223 224 225 226 227 228 |
# File 'app/models/post.rb', line 222 def absolute_public_url if Setting.for_key("rdcms.use_ssl") == "true" "https://#{Setting.for_key('rdcms.url')}#{self.public_url}" else "http://#{Setting.for_key('rdcms.url')}#{self.public_url}" end end |
#breadcrumb_name ⇒ Object
Breadcrumb **************************
208 209 210 211 212 213 214 |
# File 'app/models/post.rb', line 208 def # if self.breadcrumb.present? # return self.breadcrumb # else return self.name # end end |
#complete_json ⇒ Object
128 129 130 |
# File 'app/models/post.rb', line 128 def complete_json end |
#get_related_object ⇒ Object
Tipos de artigos ************************** Gets the related object by post_type
151 152 153 154 155 156 157 |
# File 'app/models/post.rb', line 151 def if self.post_type.present? && self.post_type_form_file.present? && self.respond_to?(self.post_type_form_file.downcase) return self.send(self.post_type_form_file.downcase) else return nil end end |
#kind_of_post_type ⇒ Object
Retorna índice ou mostrar, dependendo do tipo de página
165 166 167 |
# File 'app/models/post.rb', line 165 def kind_of_post_type self.post_type.present? ? self.post_type.split(" ").last : "" end |
#metatag(name) ⇒ Object
Metatag **************************
273 274 275 276 277 |
# File 'app/models/post.rb', line 273 def (name) return "" if !MetatagNames.include?(name) = self..find_by_name(name) .value if end |
#notification_event_create ⇒ Object
140 141 142 |
# File 'app/models/post.rb', line 140 def notification_event_create ActiveSupport::Notifications.instrument("rdcms.post.created", :post_id => self.id) end |
#notification_event_update ⇒ Object
144 145 146 |
# File 'app/models/post.rb', line 144 def notification_event_update ActiveSupport::Notifications.instrument("rdcms.post.updated", :post_id => self.id) end |
#post_type_for_search ⇒ Object
Retorna os nomes das categorias, independente de pagina de visualização ou de indice
170 171 172 173 174 175 176 |
# File 'app/models/post.rb', line 170 def post_type_for_search if self.post_type.present? self.post_type.split(" ").first else "Post" end end |
#post_type_form_file ⇒ Object
Exibe Consultor | Filial | etc. dependendo do tipo de página
160 161 162 |
# File 'app/models/post.rb', line 160 def post_type_form_file self.post_type.split(" ").first if self.post_type.present? end |
#public_url ⇒ Object
URL **************************
218 219 220 |
# File 'app/models/post.rb', line 218 def public_url post_path(self) end |
#respond_to_all?(method_name) ⇒ Boolean
Instance Methods **************************
103 104 105 106 107 108 109 |
# File 'app/models/post.rb', line 103 def respond_to_all?(method_name) begin return eval("self.#{method_name}.present?") rescue return false end end |
#searchable_in_post_type ⇒ Object
Pesquisa ************************** Especifica uma cadeia de texto a ser pesquisado no artigo
282 283 284 285 286 287 288 289 290 291 |
# File 'app/models/post.rb', line 282 def searchable_in_post_type @searchable_in_post_type_result ||= begin = self. if && .respond_to?(:fulltext_searchable_text) .fulltext_searchable_text else " " end end end |
#set_active_since ⇒ Object
124 125 126 |
# File 'app/models/post.rb', line 124 def set_active_since self.active_since = self.created_at end |
#set_default_opengraph_values ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'app/models/post.rb', line 246 def set_default_opengraph_values if Metatag.where(post_id: self.id, name: 'OpenGraph Title').none? Metatag.create( name: 'OpenGraph Title', post_id: self.id, value: self.name) end if Metatag.where(post_id: self.id, name: 'OpenGraph URL').none? Metatag.create( name: 'OpenGraph URL', post_id: self.id, value: self.absolute_public_url) end if Metatag.where(post_id: self.id, name: 'OpenGraph Description').none? if self.summary.present? value = self.summary.truncate(255) else value = self.body.present? ? self.body.truncate(255) : self.name end Metatag.create( name: 'OpenGraph Description', post_id: self.id, value: value) end end |
#translations_attributes=(attributes) ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/post.rb', line 58 def translations_attributes=(attributes) new_translations = attributes.values.reduce({}) do |new_values, translation| new_values.merge! translation.delete("locale") => translation end set_translations new_translations end |
#verify_existence_of_opengraph_image ⇒ Object
OpenGraph **************************
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'app/models/post.rb', line 232 def verify_existence_of_opengraph_image if Metatag.where("post_id = ? AND name = 'OpenGraph Image'", self.id).count == 0 Metatag.create( post_id: self.id, name: "OpenGraph Image", value: Setting.for_key("rdcms.facebook.opengraph_default_image")) end if self.posts? = Metatag.where(post_id: self.id, name: "OpenGraph Image").first .value = "#{self.posts(:thumb).to_s}" .save end end |