Class: Para::SeoTools::PageScoping
- Inherits:
-
Object
- Object
- Para::SeoTools::PageScoping
- Defined in:
- lib/para/seo_tools/page_scoping.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #alternate_language_siblings ⇒ Object
-
#initialize(resource) ⇒ PageScoping
constructor
A new instance of PageScoping.
- #scoped? ⇒ Boolean
- #unique_identifier ⇒ Object
- #uniqueness_scope_conditions ⇒ Object
Constructor Details
#initialize(resource) ⇒ PageScoping
Returns a new instance of PageScoping.
9 10 11 |
# File 'lib/para/seo_tools/page_scoping.rb', line 9 def initialize(resource) @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/para/seo_tools/page_scoping.rb', line 7 def resource @resource end |
Class Method Details
.column?(resource_class, attribute) ⇒ Boolean
44 45 46 |
# File 'lib/para/seo_tools/page_scoping.rb', line 44 def self.column?(resource_class, attribute) resource_class.column_names.include?(attribute.to_s) end |
.scope_with(resource_class, attributes) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/para/seo_tools/page_scoping.rb', line 34 def self.scope_with(resource_class, attributes) attributes.reduce(resource_class) do |query, (attribute, value)| if column?(resource_class, attribute) query.where(attribute => value) else query.where("config->>'#{ attribute }' = ?", value) end end end |
Instance Method Details
#alternate_language_siblings ⇒ Object
29 30 31 32 |
# File 'lib/para/seo_tools/page_scoping.rb', line 29 def alternate_language_siblings attributes = resource.scope_attributes.reject { |attribute, _| attribute == 'locale' } self.class.scope_with(resource.siblings, attributes) end |
#scoped? ⇒ Boolean
13 14 15 |
# File 'lib/para/seo_tools/page_scoping.rb', line 13 def scoped? resource.scope.present? end |
#unique_identifier ⇒ Object
23 24 25 26 27 |
# File 'lib/para/seo_tools/page_scoping.rb', line 23 def unique_identifier return resource.identifier unless scoped? resource.scope_attributes.merge(identifier: resource.identifier).to_json end |
#uniqueness_scope_conditions ⇒ Object
17 18 19 20 21 |
# File 'lib/para/seo_tools/page_scoping.rb', line 17 def uniqueness_scope_conditions return resource.class unless scoped? self.class.scope_with(resource.class, resource.scope_attributes) end |