class Para::SeoTools::PageScoping
Attributes
resource[R]
Public Class Methods
column?(resource_class, attribute)
click to toggle source
# 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
new(resource)
click to toggle source
# File lib/para/seo_tools/page_scoping.rb, line 9 def initialize(resource) @resource = resource end
scope_with(resource_class, attributes)
click to toggle source
# 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
Public Instance Methods
alternate_language_siblings()
click to toggle source
# 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?()
click to toggle source
# File lib/para/seo_tools/page_scoping.rb, line 13 def scoped? resource.scope.present? end
unique_identifier()
click to toggle source
# 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()
click to toggle source
# 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