Module: WithUsages

Extended by:
ActiveSupport::Concern
Included in:
Content
Defined in:
app/models/concerns/with_usages.rb

Instance Method Summary collapse

Instance Method Details

#content_used_in?(organization) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/concerns/with_usages.rb', line 23

def content_used_in?(organization)
  navigable_content_in(organization).present?
end


19
20
21
# File 'app/models/concerns/with_usages.rb', line 19

def navigable_content_in(organization = Organization.current)
  self if used_in?(organization)
end

#usage_in_organization(organization = Organization.current) ⇒ Object



10
11
12
# File 'app/models/concerns/with_usages.rb', line 10

def usage_in_organization(organization = Organization.current)
  usages_in_organization(organization).first.try(:parent_item)
end

#usage_in_organization_of_type(type, organization = Organization.current) ⇒ Object



14
15
16
17
# File 'app/models/concerns/with_usages.rb', line 14

def usage_in_organization_of_type(type, organization = Organization.current)
  item = usage_in_organization(organization)
  item.is_a?(type) ? item : nil
end

#used_in?(organization) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/concerns/with_usages.rb', line 27

def used_in?(organization)
  usage_in_organization(organization).present?
end