<commit_before>class FbAppPlugin::PageTab < ActiveRecord::Base

  # FIXME: rename table to match model
  self.table_name = :fb_app_plugin_page_tab_configs

  attr_accessible :owner_profile, :name, :profile, :profile_id, :page_id, :config_type, :profile_ids, :query

  belongs_to :owner_profile, foreign_key: :profile_id, class_name: 'Profile'

  acts_as_having_settings field: :config

  ConfigTypes = [:profile, :profiles, :query]

  validates_presence_of :page_id
  validates_uniqueness_of :page_id
  validates_inclusion_of :config_type, in: ConfigTypes

  def self.page_ids_from_tabs_added tabs_added
    tabs_added.map{ |id, value| id }
  end

  def self.create_from_page_ids page_ids, attrs = {}
    attrs.delete :page_id
    page_ids.map do |page_id|
      page_tab = FbAppPlugin::PageTab.where(page_id: page_id).first
      page_tab ||= FbAppPlugin::PageTab.new page_id: page_id
      page_tab.update_attributes! attrs
      page_tab
    end
  end
  def self.create_from_tabs_added tabs_added, attrs = {}
    page_ids = self.page_ids_from_tabs_added tabs_added
    self.create_from_page_ids page_ids, attrs
  end

  def config_type
    self.config[:type] || :profile
  end
  def config_type= value
    # ignored, set by specific methods belows
  end

  def value
    self.send self.config_type rescue nil
  end
  def blank?
    self.value.blank? rescue true
  end

  def profiles
    Profile.where(id: self.config[:profile_ids])
  end
  def profile
    self.profiles.first
  end
  def profile_ids
    self.profiles.map(&:id)
  end

  def query
    self.config[:query]
  end

  def name
    self.config[:name]
  end
  def name= value
    self.config[:name] = value
  end

  def profile_ids= ids
    ids = ids.split(',')
    self.config[:type] = if ids.size == 1 then :profile else :profiles end
    self.config[:profile_ids] = ids
  end

  def profiles= profiles
    self.config[:type] = :profiles
    self.config[:profile_ids] = profiles.map(&:id)
  end

  def profile= profile
    self.config[:type] = :profile
    self.config[:profile_ids] = [profile.id]
  end

  def query= value
    self.config[:type] = :query
    self.config[:query] = value
  end

end
<commit_msg>Add own profile and title + subtitle<commit_after>class FbAppPlugin::PageTab < ActiveRecord::Base

  # FIXME: rename table to match model
  self.table_name = :fb_app_plugin_page_tab_configs

  attr_accessible :owner_profile, :title, :subtitle, :own_profile, :profile, :profile_id, :page_id, :config_type, :profile_ids, :query

  belongs_to :owner_profile, foreign_key: :profile_id, class_name: 'Profile'

  acts_as_having_settings field: :config

  ConfigTypes = [:own_profile, :profile, :profiles, :query]

  validates_presence_of :page_id
  validates_uniqueness_of :page_id
  validates_inclusion_of :config_type, in: ConfigTypes

  def self.page_ids_from_tabs_added tabs_added
    tabs_added.map{ |id, value| id }
  end

  def self.create_from_page_ids page_ids, attrs = {}
    attrs.delete :page_id
    page_ids.map do |page_id|
      page_tab = FbAppPlugin::PageTab.where(page_id: page_id).first
      page_tab ||= FbAppPlugin::PageTab.new page_id: page_id
      page_tab.update_attributes! attrs
      page_tab
    end
  end
  def self.create_from_tabs_added tabs_added, attrs = {}
    page_ids = self.page_ids_from_tabs_added tabs_added
    self.create_from_page_ids page_ids, attrs
  end

  def config_type
    self.config[:type] || (self.owner_profile ? :own_profile : :profile)
  end
  def config_type= value
    # ignored, set by specific methods belows
  end

  def value
    self.send self.config_type rescue nil
  end
  def blank?
    self.value.blank? rescue true
  end

  def profiles
    Profile.where(id: self.config[:profile_ids])
  end
  def profile
    self.profiles.first
  end
  def profile_ids
    self.profiles.map(&:id)
  end
  def query
    self.config[:query]
  end
  def title
    self.config[:title]
  end
  def title= value
    self.config[:title] = value
  end
  def profile_ids= ids
    ids = ids.split(',')
    self.config[:type] = if ids.size == 1 then :profile else :profiles end
    self.config[:profile_ids] = ids
  end

  def profiles= profiles
    self.config[:type] = :profiles
    self.config[:profile_ids] = profiles.map(&:id)
  end

  def profile= profile
    self.config[:type] = :profile
    self.config[:profile_ids] = [profile.id]
  end

  def query= value
    self.config[:type] = :query
    self.config[:query] = value
  end

end

{'fraction_non_alphanumeric': 0.09582585278276481, 'fraction_numerical': 0.0004488330341113106, 'mean_word_length': 3.68172268907563, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2004886', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1538, 'n_words': 366}