Class: Redde::Seo::Finder::Objected
- Inherits:
-
Object
- Object
- Redde::Seo::Finder::Objected
- Defined in:
- app/models/redde/seo/finder/objected.rb
Instance Attribute Summary collapse
-
#objekt ⇒ Object
Returns the value of attribute objekt.
-
#seo ⇒ Object
Returns the value of attribute seo.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #create_seo ⇒ Object
- #default_seo ⇒ Object
- #find ⇒ Object
-
#initialize(url, objekt) ⇒ Objected
constructor
A new instance of Objected.
- #object_class_name ⇒ Object
- #objekt_params ⇒ Object
- #seo_params ⇒ Object
- #templated? ⇒ Boolean
- #templated_seo ⇒ Object
- #updated_object_seo ⇒ Object
Constructor Details
#initialize(url, objekt) ⇒ Objected
Returns a new instance of Objected.
6 7 8 9 10 |
# File 'app/models/redde/seo/finder/objected.rb', line 6 def initialize(url, objekt) @url = url @objekt = objekt @seo = Redde::Seo.for_object(objekt).first end |
Instance Attribute Details
#objekt ⇒ Object
Returns the value of attribute objekt.
4 5 6 |
# File 'app/models/redde/seo/finder/objected.rb', line 4 def objekt @objekt end |
#seo ⇒ Object
Returns the value of attribute seo.
4 5 6 |
# File 'app/models/redde/seo/finder/objected.rb', line 4 def seo @seo end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'app/models/redde/seo/finder/objected.rb', line 4 def url @url end |
Instance Method Details
#create_seo ⇒ Object
48 49 50 51 |
# File 'app/models/redde/seo/finder/objected.rb', line 48 def create_seo s = Redde::Seo.new(seo_params.merge(skip_basic_validation: true)) s.save if objekt.try(:id) && objekt.try(:class).try(:name) end |
#default_seo ⇒ Object
19 20 21 |
# File 'app/models/redde/seo/finder/objected.rb', line 19 def default_seo Redde::Seo::DefaultSeo.new end |
#find ⇒ Object
12 13 14 15 16 17 |
# File 'app/models/redde/seo/finder/objected.rb', line 12 def find return updated_object_seo if seo && !seo.empty? return templated_seo if templated? create_seo default_seo end |
#object_class_name ⇒ Object
28 29 30 |
# File 'app/models/redde/seo/finder/objected.rb', line 28 def object_class_name objekt.class.name end |
#objekt_params ⇒ Object
40 41 42 |
# File 'app/models/redde/seo/finder/objected.rb', line 40 def objekt_params { seoable_id: objekt.id, seoable_type: objekt.class.name } end |
#seo_params ⇒ Object
44 45 46 |
# File 'app/models/redde/seo/finder/objected.rb', line 44 def seo_params objekt_params.merge(url: url) end |
#templated? ⇒ Boolean
32 33 34 |
# File 'app/models/redde/seo/finder/objected.rb', line 32 def templated? Redde::Seo::CustomClassNames::NAMES.include? object_class_name end |
#templated_seo ⇒ Object
36 37 38 |
# File 'app/models/redde/seo/finder/objected.rb', line 36 def templated_seo "Redde::Seo::#{object_class_name}Seo".constantize.new(objekt) end |
#updated_object_seo ⇒ Object
23 24 25 26 |
# File 'app/models/redde/seo/finder/objected.rb', line 23 def updated_object_seo seo.update(url: url) if seo.url != url seo end |