<commit_before>require 'rails'
require 'rest_client'
require 'highline/import'
require "innsights/version"

module Innsights
  
  module Helpers
    autoload :Tasks,            'innsights/helpers/tasks'
    autoload :Config,           'innsights/helpers/config'
  end
  
  module Actions
    autoload :User,             'innsights/actions/user'
    autoload :Group,            'innsights/actions/group'
  end
  
  module Config
    autoload :Report,           'innsights/config/reports/report'
    autoload :ModelReport,      'innsights/config/reports/model_report'
    autoload :ControllerReport, 'innsights/config/reports/controller_report'
    autoload :GenericReport,    'innsights/config/reports/generic_report'
    autoload :User,             'innsights/config/user'
    autoload :Group,            'innsights/config/group'
  end

  autoload :ErrorMessage,       'innsights/error_message.rb'
  
  autoload :Action,             'innsights/action'
  autoload :Metric,             'innsights/metric'
  autoload :Client,             'innsights/client'

  ## Configuration defaults
  mattr_accessor :user_call
  @@user_call = :user
  
  mattr_accessor :user_id
  @@user_id = :id
  
  mattr_accessor :user_display
  @@user_display = :to_s
  
  mattr_accessor :group_call
  @@group_call = nil
  
  mattr_accessor :group_id
  @@group_id = :id
  
  mattr_accessor :group_display
  @@group_display = :to_s
  
  mattr_accessor :reports
  @@reports = []
  
  mattr_accessor :enabled
  @@enabled = { development: true, test: true, staging:true, production:true }[Rails.env.to_sym]
  
  mattr_accessor :debugging
  @@debugging = false
  
  mattr_accessor :url
  @@url = "innsights.me"
  
  mattr_accessor :client
  
  mattr_accessor :queue_system
  @@queue_system = nil
  @@supported_queue_systems = [:delayed_job, :resque]

  # Configured subdomain of the client app
  # @return [String] subdomain of current app
  def self.app_subdomain
    @@app_subdomain ||= credentials["app"]
  end
  
  # Configured token of client app
  # @return [String] authentication token of app
  def self.app_token
    @@app_token ||= credentials["token"]
  end

  # Configuration variables of client app
  # @return [Hash] containing the subdomain and authentication token of app
  def self.credentials
    @@credentials ||= YAML.load(File.open(File.join(Rails.root, 'config/innsights.yml')))["credentials"]
  end
  
  # Final url to post actions to, includes the rails app environment
  # @return [String] contains app subdomain, innsights url and client app environment
  def self.app_url
    "#{app_subdomain}." << @@url << "/#{Rails.env}"
  end

  # Defines the url for test_mode
  # @return [String] contains the test url
  def self.test_url
    "innsights.dev"
  end
  
  # Sets testing environment on for local server development
  # @param [true,false] on testing on or off
  # @return [String] with local server url if on, nil if off
  mattr_reader :test_mode
  def self.test_mode=(on)
    @@test_mode = on
    @@url = test_url if on
  end
  
  # Main configuration method to create all event watchers
  # @yield Configuration for
  #   * App user class
  #   * Appp action reports
  def self.setup(&block)
    self.instance_eval(&block)
    self.client = Client.new(url, app_subdomain, app_token, Rails.env)
  end

  # Extra configuration for custom experience
  # @yield Configuration for
  #   * Queue system
  #   * Test mode
  def self.config(*envs, &block)
    self.instance_eval(&block) if envs.blank?
    envs.each do |env| 
      self.instance_eval(&block) if Rails.env == env.to_s
    end
  end
  
  # Sets up the user class and configures the display and group
  # @yield Configuration for
  #   * display
  #   * id
  #   * group
  def self.user(klass, &block)
    self.user_call = klass.to_s.downcase.to_sym
    Config::User.class_eval(&block) if block_given? 
  end

  # Sets up an event observer for creating an action on Innsights
  # @yield Configuration for
  #   * Action Name
  #   * Timestamp
  #   * User call
  #   * Event Trigger
  def self.watch(klass, params={}, &block)
    report = Config::ModelReport.new(params[:class] || klass)
    report.instance_eval(&block)
    report.commit
  end

  # Sets up an event observer for creating an custom action on Innsights
  # @yield Configuration for
  #   * Action Name
  #   * Timestamp
  #   * User call
  #   * Event Trigger
  def self.on(catalyst, &block)
    report = Config::ControllerReport.new(catalyst)
    report.instance_eval(&block)
    report.commit
  end

  # Sets up the user class and configures the display and group
  # @param [:resque, :delayed_job]
  def self.queue(queue='')
    if @@supported_queue_systems.include?(queue)
      self.queue_system = queue 
    end
  end

  def self.test(test_mode='')
    self.test_mode = test_mode
  end
  
  # Creates and commit a GenericReport
  # @param [:name, :user]
  # @return [Innsights::Config::GenericReport]
  def self.report(name, options={})
    report = Innsights::Config::GenericReport.new(name, options)
    report.commit
    report
  end
  
  if defined?(Rails)
    require 'innsights/railtie'
  end
    
end<commit_msg>Adds mode method for staging and test modes<commit_after>require 'rails'
require 'rest_client'
require 'highline/import'
require "innsights/version"

module Innsights
  
  module Helpers
    autoload :Tasks,            'innsights/helpers/tasks'
    autoload :Config,           'innsights/helpers/config'
  end
  
  module Actions
    autoload :User,             'innsights/actions/user'
    autoload :Group,            'innsights/actions/group'
  end
  
  module Config
    autoload :Report,           'innsights/config/reports/report'
    autoload :ModelReport,      'innsights/config/reports/model_report'
    autoload :ControllerReport, 'innsights/config/reports/controller_report'
    autoload :GenericReport,    'innsights/config/reports/generic_report'
    autoload :User,             'innsights/config/user'
    autoload :Group,            'innsights/config/group'
  end

  autoload :ErrorMessage,       'innsights/error_message.rb'
  
  autoload :Action,             'innsights/action'
  autoload :Metric,             'innsights/metric'
  autoload :Client,             'innsights/client'

  ## Configuration defaults
  mattr_accessor :user_call
  @@user_call = :user
  
  mattr_accessor :user_id
  @@user_id = :id
  
  mattr_accessor :user_display
  @@user_display = :to_s
  
  mattr_accessor :group_call
  @@group_call = nil
  
  mattr_accessor :group_id
  @@group_id = :id
  
  mattr_accessor :group_display
  @@group_display = :to_s
  
  mattr_accessor :reports
  @@reports = []
  
  mattr_accessor :enabled
  @@enabled = { development: true, test: true, staging:true, production:true }[Rails.env.to_sym]
  
  mattr_accessor :debugging
  @@debugging = false
  
  mattr_accessor :url
  @@url = "innsights.me"
  
  mattr_accessor :test_url
  @@test_url = "innsights.dev"
  
  mattr_accessor :staging_url
  @@staging_url = "innsights.info"
  
  mattr_accessor :client
  
  mattr_accessor :queue_system
  @@queue_system = nil
  @@supported_queue_systems = [:delayed_job, :resque]

  # Configured subdomain of the client app
  # @return [String] subdomain of current app
  def self.app_subdomain
    @@app_subdomain ||= credentials["app"]
  end
  
  # Configured token of client app
  # @return [String] authentication token of app
  def self.app_token
    @@app_token ||= credentials["token"]
  end

  # Configuration variables of client app
  # @return [Hash] containing the subdomain and authentication token of app
  def self.credentials
    @@credentials ||= YAML.load(File.open(File.join(Rails.root, 'config/innsights.yml')))["credentials"]
  end
  
  # Final url to post actions to, includes the rails app environment
  # @return [String] contains app subdomain, innsights url and client app environment
  def self.app_url
    "#{app_subdomain}." << @@url << "/#{Rails.env}"
  end
  
  # Sets testing environment on for local server development
  # @param [true,false] on testing on or off
  # @return [String] with local server url if on, nil if off
  mattr_reader :test_mode
  def self.mode(mode)
    if mode == :staging || mode == :test
      @@test_mode = true
      @@url = eval("#{mode}_url")
    end
  end
  
  # Main configuration method to create all event watchers
  # @yield Configuration for
  #   * App user class
  #   * Appp action reports
  def self.setup(&block)
    self.instance_eval(&block)
    self.client = Client.new(url, app_subdomain, app_token, Rails.env)
  end

  # Extra configuration for custom experience
  # @yield Configuration for
  #   * Queue system
  #   * Test mode
  def self.config(*envs, &block)
    self.instance_eval(&block) if envs.blank?
    envs.each do |env| 
      self.instance_eval(&block) if Rails.env == env.to_s
    end
  end
  
  # Sets up the user class and configures the display and group
  # @yield Configuration for
  #   * display
  #   * id
  #   * group
  def self.user(klass, &block)
    self.user_call = klass.to_s.downcase.to_sym
    Config::User.class_eval(&block) if block_given? 
  end

  # Sets up an event observer for creating an action on Innsights
  # @yield Configuration for
  #   * Action Name
  #   * Timestamp
  #   * User call
  #   * Event Trigger
  def self.watch(klass, params={}, &block)
    report = Config::ModelReport.new(params[:class] || klass)
    report.instance_eval(&block)
    report.commit
  end

  # Sets up an event observer for creating an custom action on Innsights
  # @yield Configuration for
  #   * Action Name
  #   * Timestamp
  #   * User call
  #   * Event Trigger
  def self.on(catalyst, &block)
    report = Config::ControllerReport.new(catalyst)
    report.instance_eval(&block)
    report.commit
  end

  # Sets up the user class and configures the display and group
  # @param [:resque, :delayed_job]
  def self.queue(queue='')
    if @@supported_queue_systems.include?(queue)
      self.queue_system = queue 
    end
  end
  
  # Creates and commit a GenericReport
  # @param [:name, :user]
  # @return [Innsights::Config::GenericReport]
  def self.report(name, options={})
    report = Innsights::Config::GenericReport.new(name, options)
    report.commit
    report
  end
  
  if defined?(Rails)
    require 'innsights/railtie'
  end
    
end
{'fraction_non_alphanumeric': 0.09919519053621642, 'fraction_numerical': 0.0, 'mean_word_length': 3.165589660743134, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1825485', 'n_tokens_mistral': 3483, 'n_tokens_neox': 3389, 'n_words': 884}