Module: Configuration::Methods

Defined in:
lib/configuration_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configured_servicesObject


23
24
25
26
27
28
29
30
31
32
# File 'lib/configuration_methods.rb', line 23

def configured_services
  return @configured_services unless @configured_services.nil?

  @configured_services = []
  [:twitter, :tumblr, :facebook, :wordpress].each do |service|
    @configured_services << service if services.send(service).enable?
  end

  @configured_services
end

#git_revisionObject


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

def git_revision
  get_git_info if git_available?
  @git_revision
end

#git_updateObject


79
80
81
82
# File 'lib/configuration_methods.rb', line 79

def git_update
  get_git_info if git_available?
  @git_update
end

Instance Method Details

#bare_pod_uriObject


19
20
21
# File 'lib/configuration_methods.rb', line 19

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

#bitcoin_donation_addressObject


124
125
126
127
128
129
130
131
132
133
# File 'lib/configuration_methods.rb', line 124

def bitcoin_donation_address
  if AppConfig.settings.bitcoin_wallet_id.present?
    warn "WARNING: bitcoin_wallet_id is now bitcoin_address. Change in diaspora.yml."
    return AppConfig.settings.bitcoin_wallet_id
  end

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

#get_redis_optionsObject


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/configuration_methods.rb', line 89

def get_redis_options
  if redistogo_url.present?
    warn "WARNING: using the REDISTOGO_URL environment variable is deprecated, please use REDIS_URL now."
    ENV['REDIS_URL'] = redistogo_url
  end

  redis_options = {}

  redis_url = ENV['REDIS_URL'] || environment.redis.get

  if ENV['RAILS_ENV']== 'integration2'
    redis_options[:url] = "redis://localhost:6380"
  elsif redis_url.present?
    unless redis_url.start_with?("redis://") || redis_url.start_with?("unix:///")
      warn "WARNING: Your redis url (#{redis_url}) doesn't start with redis:// or unix:///"
    end
    redis_options[:url] = redis_url
  end

  redis_options[:namespace] = AppConfig.environment.sidekiq.namespace.get

  redis_options
end

#git_available?Boolean


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/configuration_methods.rb', line 61

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

#pod_uriObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/configuration_methods.rb', line 3

def pod_uri
  return @pod_uri unless @pod_uri.nil?

  url = environment.url.get
  url = "http://#{url}" unless url =~ /^(https?:\/\/)/
  url << "/" unless url.end_with?("/")

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

  @pod_url
end

#postgres?Boolean


119
120
121
122
# File 'lib/configuration_methods.rb', line 119

def postgres?
  defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
  ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
end

#rails_asset_idObject


85
86
87
# File 'lib/configuration_methods.rb', line 85

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

#secret_tokenObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/configuration_methods.rb', line 35

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)}"
    Process.exit(1)
  else
    token_file = File.expand_path(
      '../config/initializers/secret_token.rb',
      File.dirname(__FILE__)
    )
    unless File.exist? token_file
      `bundle exec rake generate:secret_token`
    end
    require token_file
    Rails.application.config.secret_token
  end
end

#sidekiq_logObject


113
114
115
116
117
# File 'lib/configuration_methods.rb', line 113

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

#version_stringObject


54
55
56
57
58
59
# File 'lib/configuration_methods.rb', line 54

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