<commit_before>module Locomotive
  class Site

    include Locomotive::Mongoid::Document

    ## Extensions ##
    include Concerns::Shared::Seo
    include Concerns::Site::AccessPoints
    include Concerns::Site::Locales
    include Concerns::Site::Timezone
    include Concerns::Site::Cache
    include Concerns::Site::UrlRedirections
    include Concerns::Site::PrivateAccess
    include Concerns::Site::Metafields

    ## fields ##
    field :name
    field :robots_txt

    mount_uploader :picture, PictureUploader, validate_integrity: true

    ## associations ##
    belongs_to  :created_by,      class_name: 'Locomotive::Account'
    embeds_many :memberships,     class_name: 'Locomotive::Membership'
    has_many    :pages,           class_name: 'Locomotive::Page',           validate: false, autosave: false
    has_many    :snippets,        class_name: 'Locomotive::Snippet',        dependent: :destroy, validate: false, autosave: false
    has_many    :theme_assets,    class_name: 'Locomotive::ThemeAsset',     dependent: :destroy, validate: false, autosave: false
    has_many    :content_assets,  class_name: 'Locomotive::ContentAsset',   dependent: :destroy, validate: false, autosave: false
    has_many    :content_types,   class_name: 'Locomotive::ContentType',    dependent: :destroy, validate: false, autosave: false
    has_many    :content_entries, class_name: 'Locomotive::ContentEntry',   dependent: :destroy, validate: false, autosave: false
    has_many    :translations,    class_name: 'Locomotive::Translation',    dependent: :destroy, validate: false, autosave: false
    has_many    :activities,      class_name: 'Locomotive::Activity',       dependent: :destroy, validate: false, autosave: false

    ## validations ##
    validates_presence_of :name

    ## callbacks ##
    after_create    :create_default_pages!
    after_destroy   :destroy_pages

    ## behaviours ##
    accepts_nested_attributes_for :memberships, allow_destroy: true

    ## methods ##

    # Get all the pages in the right order: depth and position, both ASC.
    #
    # @param [ Hash ] conditions Extra conditions passed to the Mongoid criteria
    #
    # @return [ Criteria ] a Mongoid criteria
    #
    def ordered_pages(conditions = {})
      self.pages.unscoped.where(conditions || {}).order_by_depth_and_position
    end

    def fetch_page(path, logged_in)
      Locomotive::Page.fetch_page_from_path self, path, logged_in
    end

    def localized_content_types
      self.content_types.localized
    end

    def accounts
      Account.criteria.in(_id: self.memberships.map(&:account_id))
    end

    def membership_for(account)
      self.memberships.where(account_id: account._id).first
    end

    def admin_memberships
      self.memberships.find_all { |m| m.admin? }
    end

    def is_admin?(account)
      self.memberships.detect { |m| m.admin? && m.account_id == account._id }
    end

    def to_steam
      repository = Locomotive::Steam::Services.build_instance.repositories.site
      repository.build(self.attributes.dup)
    end

    def to_liquid<commit_msg>remove dead method (fix issue #1159)<commit_after>module Locomotive
  class Site

    include Locomotive::Mongoid::Document

    ## Extensions ##
    include Concerns::Shared::Seo
    include Concerns::Site::AccessPoints
    include Concerns::Site::Locales
    include Concerns::Site::Timezone
    include Concerns::Site::Cache
    include Concerns::Site::UrlRedirections
    include Concerns::Site::PrivateAccess
    include Concerns::Site::Metafields

    ## fields ##
    field :name
    field :robots_txt

    mount_uploader :picture, PictureUploader, validate_integrity: true

    ## associations ##
    belongs_to  :created_by,      class_name: 'Locomotive::Account'
    embeds_many :memberships,     class_name: 'Locomotive::Membership'
    has_many    :pages,           class_name: 'Locomotive::Page',           validate: false, autosave: false
    has_many    :snippets,        class_name: 'Locomotive::Snippet',        dependent: :destroy, validate: false, autosave: false
    has_many    :theme_assets,    class_name: 'Locomotive::ThemeAsset',     dependent: :destroy, validate: false, autosave: false
    has_many    :content_assets,  class_name: 'Locomotive::ContentAsset',   dependent: :destroy, validate: false, autosave: false
    has_many    :content_types,   class_name: 'Locomotive::ContentType',    dependent: :destroy, validate: false, autosave: false
    has_many    :content_entries, class_name: 'Locomotive::ContentEntry',   dependent: :destroy, validate: false, autosave: false
    has_many    :translations,    class_name: 'Locomotive::Translation',    dependent: :destroy, validate: false, autosave: false
    has_many    :activities,      class_name: 'Locomotive::Activity',       dependent: :destroy, validate: false, autosave: false

    ## validations ##
    validates_presence_of :name

    ## callbacks ##
    after_create    :create_default_pages!
    after_destroy   :destroy_pages

    ## behaviours ##
    accepts_nested_attributes_for :memberships, allow_destroy: true

    ## methods ##

    # Get all the pages in the right order: depth and position, both ASC.
    #
    # @param [ Hash ] conditions Extra conditions passed to the Mongoid criteria
    #
    # @return [ Criteria ] a Mongoid criteria
    #
    def ordered_pages(conditions = {})
      self.pages.unscoped.where(conditions || {}).order_by_depth_and_position
    end

    def localized_content_types
      self.content_types.localized
    end

    def accounts
      Account.criteria.in(_id: self.memberships.map(&:account_id))
    end

    def membership_for(account)
      self.memberships.where(account_id: account._id).first
    end

    def admin_memberships
      self.memberships.find_all { |m| m.admin? }
    end

    def is_admin?(account)
      self.memberships.detect { |m| m.admin? && m.account_id == account._id }
    end

    def to_steam
      repository = Locomotive::Steam::Services.build_instance.repositories.site
      repository.build(self.attributes.dup)
    end

    def to_liquid
{'fraction_non_alphanumeric': 0.09783677482792527, 'fraction_numerical': 0.0006555227794165847, 'mean_word_length': 3.5544776119402983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369052', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1804, 'n_words': 418}