Module: Configuration::Methods

Defined in:
lib/configuration_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configured_servicesObject


34
35
36
37
38
39
40
41
42
43
# File 'lib/configuration_methods.rb', line 34

def configured_services
  return @configured_services unless @configured_services.nil?

  @configured_services = []
  KNOWN_SERVICES.each do |service|
    @configured_services << service if services.send(service).enable?
  end

  @configured_services
end

Instance Method Details

#bare_pod_uriObject


30
31
32
# File 'lib/configuration_methods.rb', line 30

def bare_pod_uri
  pod_uri.authority.gsub('www.', '')
end

#bitcoin_donation_addressObject


130
131
132
133
134
# File 'lib/configuration_methods.rb', line 130

def bitcoin_donation_address
  if AppConfig.settings.bitcoin_address.present?
    AppConfig.settings.bitcoin_address
  end
end

#get_redis_optionsObject


105
106
107
108
109
110
111
112
113
114
# File 'lib/configuration_methods.rb', line 105

def get_redis_options
  redis_url = ENV["REDIS_URL"] || environment.redis.get

  return {} unless redis_url.present?

  unless redis_url.start_with?("redis://", "unix:///")
    warn "WARNING: Your redis url (#{redis_url}) doesn't start with redis:// or unix:///"
  end
  {url: redis_url}
end

#git_available?Boolean

Returns:

  • (Boolean)

79
80
81
82
83
84
85
86
87
88
89
# File 'lib/configuration_methods.rb', line 79

def git_available?
  return @git_available unless @git_available.nil?

  if heroku?
    @git_available = false
  else
    `which git`
    `git status 2> /dev/null` if $?.success?
    @git_available = $?.success?
  end
end

#git_revisionObject


91
92
93
94
# File 'lib/configuration_methods.rb', line 91

def git_revision
  get_git_info if git_available?
  @git_revision
end

#git_updateObject


96
97
98
99
# File 'lib/configuration_methods.rb', line 96

def git_update
  get_git_info if git_available?
  @git_update
end

#mysql?Boolean

Returns:

  • (Boolean)

126
127
128
# File 'lib/configuration_methods.rb', line 126

def mysql?
  ActiveRecord::Base.connection.adapter_name == "Mysql2"
end

#pod_uriObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/configuration_methods.rb', line 7

def pod_uri
  return @pod_uri.dup unless @pod_uri.nil?

  url = environment.url.get

  begin
    @pod_uri = Addressable::URI.heuristic_parse(url)
  rescue
    puts "WARNING: pod url #{url} is not a legal URI"
  end

  @pod_uri.scheme = "https" if environment.require_ssl?
  @pod_uri.path = "/"

  @pod_uri.dup
end

#postgres?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'lib/configuration_methods.rb', line 122

def postgres?
  ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
end

#rails_asset_idObject


101
102
103
# File 'lib/configuration_methods.rb', line 101

def rails_asset_id
  (git_revision || version)[0..8]
end

#secret_tokenObject


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/configuration_methods.rb', line 53

def secret_token
  if heroku?
    return ENV["SECRET_TOKEN"] if ENV["SECRET_TOKEN"]

    warn "FATAL: Running on Heroku with SECRET_TOKEN unset"
    warn "       Run heroku config:add SECRET_TOKEN=#{SecureRandom.hex(40)}"
    abort
  else
    token_file = File.expand_path(
      "../config/initializers/secret_token.rb",
      File.dirname(__FILE__)
    )
    system "DISABLE_SPRING=1 bin/rake generate:secret_token" unless File.exist? token_file
    require token_file
    Diaspora::Application.config.secret_key_base
  end
end

#show_service?(service, user) ⇒ Boolean

Returns:

  • (Boolean)

46
47
48
49
50
51
# File 'lib/configuration_methods.rb', line 46

def show_service?(service, user)
  return false unless self["services.#{service}.enable"]
  # Return true only if 'authorized' is true or equal to user username
  (user && self["services.#{service}.authorized"] == user.username) ||
    self["services.#{service}.authorized"] == true
end

#sidekiq_logObject


116
117
118
119
120
# File 'lib/configuration_methods.rb', line 116

def sidekiq_log
  path = Pathname.new environment.sidekiq.log.get
  path = Rails.root.join(path) unless path.absolute?
  path.to_s
end

#url_to(path) ⇒ String

Parameters:

Returns:


26
27
28
# File 'lib/configuration_methods.rb', line 26

def url_to(path)
  pod_uri.tap {|uri| uri.path = path }.to_s
end

#version_stringObject


71
72
73
74
75
76
77
# File 'lib/configuration_methods.rb', line 71

def version_string
  return @version_string unless @version_string.nil?

  @version_string = version.number.to_s
  @version_string = "#{@version_string}-p#{git_revision[0..7]}" if git_available?
  @version_string
end