Sha256: 62b1f74113cfeb738b4e5f54b23cfc3386aefa117f11856b0bde2884b3f79b49

Contents?: true

Size: 1.77 KB

Versions: 14

Compression:

Stored size: 1.77 KB

Contents

require 'effective_resources'
require 'effective_datatables'
require 'effective_learndash/engine'
require 'effective_learndash/version'

module EffectiveLearndash
  WP_USERNAME_PROC = Proc.new { |user| "user#{user.id}" }
  WP_PASSWORD_PROC = Proc.new { |user| SecureRandom.base64(12) }

  def self.config_keys
    [
      :learndash_url, :learndash_username, :learndash_password,
      :wp_username, :wp_password,
      :layout, :per_page, :use_effective_roles,
      :course_registration_class_name
    ]
  end

  include EffectiveGem

  def self.api
    raise('please set learndash_url in config/initializers/effective_learndash.rb') unless learndash_url.present?
    raise('please set learndash_username in config/initializers/effective_learndash.rb') unless learndash_username.present?
    raise('please set learndash_password in config/initializers/effective_learndash.rb') unless learndash_password.present?

    Effective::LearndashApi.new(
      url: learndash_url,
      username: learndash_username,
      password: learndash_password
    )
  end

  def self.wp_username
    config[:wp_username] || WP_USERNAME_PROC
  end

  def self.wp_password
    config[:wp_password] || WP_PASSWORD_PROC
  end

  # The user.learndash_username is the source of truth
  # This is the backup to generate a new username
  def self.wp_username_for(owner)
    raise('expecting a learndash owner') unless owner.class.respond_to?(:effective_learndash_owner?)
    owner.instance_exec(owner, &wp_username)
  end

  def self.wp_password_for(owner)
    raise('expecting a learndash owner') unless owner.class.respond_to?(:effective_learndash_owner?)
    owner.instance_exec(owner, &wp_password)
  end

  def self.CourseRegistration
    course_registration_class_name&.constantize || Effective::CourseRegistration
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
effective_learndash-0.5.0 lib/effective_learndash.rb
effective_learndash-0.4.0 lib/effective_learndash.rb
effective_learndash-0.3.3 lib/effective_learndash.rb
effective_learndash-0.3.2 lib/effective_learndash.rb
effective_learndash-0.3.1 lib/effective_learndash.rb
effective_learndash-0.3.0 lib/effective_learndash.rb
effective_learndash-0.2.1 lib/effective_learndash.rb
effective_learndash-0.2.0 lib/effective_learndash.rb
effective_learndash-0.1.9 lib/effective_learndash.rb
effective_learndash-0.1.8 lib/effective_learndash.rb
effective_learndash-0.1.7 lib/effective_learndash.rb
effective_learndash-0.1.6 lib/effective_learndash.rb
effective_learndash-0.1.5 lib/effective_learndash.rb
effective_learndash-0.1.4 lib/effective_learndash.rb