<commit_before>module RailsRole::NameSpace
  extend ActiveSupport::Concern

  included do
    attribute :name, :string
    attribute :identifier, :string, default: 'application'
    attribute :verify_organ, :boolean, default: false
    attribute :verify_member, :boolean, default: false
    attribute :verify_user, :boolean, default: false

    has_many :governs, foreign_key: :namespace_identifier, primary_key: :identifier

    validates :identifier, uniqueness: true
  end

  def name
    if super.present?
      super
    else
      identifier
    end
  end

  def role_hash(business_identifier)
    Rule.where(business_identifier: business_identifier, namespace_identifier: identifier)
    .select(:controller_identifier, :action_name)
    .group_by(&:controller_identifier).transform_values! do |v|
      v.each_with_object({}) { |i, h| h.merge! i.action_name => true }
    end
  end

  class_methods do

    def sync
      existing = NameSpace.select(:identifier).distinct.pluck(:identifier)
      (RailsCom::Routes.namespaces.keys - existing).each do |namespace|
        namespace = NameSpace.find_or_initialize_by(identifier: namespace)
        namespace.save
      end

      (existing - RailsCom::Routes.namespaces.keys).each do |namespace|
        NameSpace.find_by(identifier: namespace).destroy
      end
    end

  end

end<commit_msg>group<commit_after>module RailsRole::NameSpace
  extend ActiveSupport::Concern

  included do
    attribute :name, :string
    attribute :identifier, :string, default: 'application'
    attribute :verify_organ, :boolean, default: false
    attribute :verify_member, :boolean, default: false
    attribute :verify_user, :boolean, default: false

    has_many :governs, foreign_key: :namespace_identifier, primary_key: :identifier

    validates :identifier, uniqueness: true
  end

  def name
    if super.present?
      super
    else
      identifier
    end
  end

  def role_hash(business_identifier)
    Rule.where(business_identifier: business_identifier, namespace_identifier: identifier)
    .select(:controller_name, :action_name)
    .group_by(&:controller_name).transform_values! do |v|
      v.each_with_object({}) { |i, h| h.merge! i.action_name => true }
    end
  end

  class_methods do

    def sync
      existing = NameSpace.select(:identifier).distinct.pluck(:identifier)
      (RailsCom::Routes.namespaces.keys - existing).each do |namespace|
        namespace = NameSpace.find_or_initialize_by(identifier: namespace)
        namespace.save
      end

      (existing - RailsCom::Routes.namespaces.keys).each do |namespace|
        NameSpace.find_by(identifier: namespace).destroy
      end
    end

  end

end
{'fraction_non_alphanumeric': 0.09179104477611941, 'fraction_numerical': 0.0, 'mean_word_length': 3.6788830715532286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7230269', 'n_tokens_mistral': 785, 'n_tokens_neox': 758, 'n_words': 185}