Class: SocialSnippet::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/social_snippet/config.rb

Constant Summary collapse

ENV_PREFIX =

prefix of environment variables

"SOCIAL_SNIPPET_"
FIELDS =
[
  # The path of home directory [default: "$HOME/.social-snippet"]
  :home,
  # Enable debug mode? [default: false]
  :debug,
  # Web API host [default: "sspm.herokuapp.com"]
  :sspm_host,
  # Web API version [default: "v0"]
  :sspm_version,
  # Web API protocol [default: "https"]
  :sspm_protocol,
]
FLAGS =

use “true” / “false”

[
  :debug,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_social_snippet, options = {}) ⇒ Config

Constructor


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/social_snippet/config.rb', line 30

def initialize(new_social_snippet, options = {})
  @social_snippet = new_social_snippet

  fields = {}
  fields.merge! options
  load_environment_variables fields

  # set default values
  fields[:home] ||= "#{ENV["HOME"]}/.social-snippet"
  fields[:sspm_host]      ||= "sspm.herokuapp.com"
  fields[:sspm_version]   ||= "v0"
  fields[:sspm_protocol]  ||= "https"

  FIELDS.each do |field_name|
    key = "@#{field_name.to_s}".to_sym
    instance_variable_set key, fields[field_name]
  end

  init_directories
end

Instance Attribute Details

#social_snippetObject (readonly)

Returns the value of attribute social_snippet


3
4
5
# File 'lib/social_snippet/config.rb', line 3

def social_snippet
  @social_snippet
end

Instance Method Details

#debug?Boolean


69
70
71
# File 'lib/social_snippet/config.rb', line 69

def debug?
  debug
end

#init_directoriesObject


63
64
65
66
67
# File 'lib/social_snippet/config.rb', line 63

def init_directories
  ::FileUtils.mkdir_p home
  ::FileUtils.mkdir_p install_path
  ::FileUtils.mkdir_p repository_cache_path
end

#install_pathObject


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

def install_path
  ::File.join home, "repo"
end

#installed_repos_fileObject


55
56
57
# File 'lib/social_snippet/config.rb', line 55

def installed_repos_file
  ::File.join home, "installed_repos.yml"
end

#repository_cache_pathObject


51
52
53
# File 'lib/social_snippet/config.rb', line 51

def repository_cache_path
  ::File.join home, "repo_cache"
end