Module: EffectiveLearndash

Includes:
EffectiveGem
Defined in:
lib/effective_learndash.rb,
lib/effective_learndash/engine.rb,
lib/effective_learndash/version.rb,
lib/generators/effective_learndash/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

WP_USERNAME_PROC =
Proc.new { |user| "user#{user.id}" }
WP_PASSWORD_PROC =
Proc.new { |user| SecureRandom.base64(12) }
VERSION =
'0.6.1'.freeze

Class Method Summary collapse

Class Method Details

.apiObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/effective_learndash.rb', line 25

def self.api
  return if disabled?

  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

.config_keysObject



10
11
12
13
14
15
16
17
# File 'lib/effective_learndash.rb', line 10

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

.CourseRegistrationObject



59
60
61
# File 'lib/effective_learndash.rb', line 59

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

.disabled?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/effective_learndash.rb', line 21

def self.disabled?
  learndash_url.blank?
end

.wp_passwordObject



43
44
45
# File 'lib/effective_learndash.rb', line 43

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

.wp_password_for(owner) ⇒ Object



54
55
56
57
# File 'lib/effective_learndash.rb', line 54

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

.wp_usernameObject



39
40
41
# File 'lib/effective_learndash.rb', line 39

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

.wp_username_for(owner) ⇒ Object

The user.learndash_username is the source of truth This is the backup to generate a new username



49
50
51
52
# File 'lib/effective_learndash.rb', line 49

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