Class: Datapimp::Configuration
- Inherits:
-
Object
- Object
- Datapimp::Configuration
show all
- Includes:
- Singleton
- Defined in:
- lib/datapimp/configuration.rb
Constant Summary
collapse
- DefaultSettings =
{
manifest_filename: "datapimp.json",
github_username: '',
github_organization: '',
github_app_key: '',
github_app_secret: '',
github_access_token: '',
dnsimple_api_token: '',
dnsimple_username: '',
dropbox_app_key: '',
dropbox_app_secret: '',
dropbox_app_type: 'sandbox',
dropbox_client_token: '',
dropbox_client_secret: '',
aws_access_key_id: '',
aws_secret_access_key: '',
aws_region: 'us-east-1',
google_client_id: '',
google_client_secret: '',
google_refresh_token: '',
google_access_token: ''
}
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/datapimp/configuration.rb', line 48
def method_missing(meth, *args, &block)
if current.key?(meth.to_s)
return current.fetch(meth)
end
super
end
|
Class Method Details
.method_missing(meth, *args, &block) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/datapimp/configuration.rb', line 40
def self.method_missing(meth, *args, &block)
if instance.respond_to?(meth)
return instance.send meth, *args, &block
end
nil
end
|
Instance Method Details
#amazon_setup? ⇒ Boolean
88
89
90
|
# File 'lib/datapimp/configuration.rb', line 88
def amazon_setup?
aws_access_key_id.to_s.length > 0 && aws_secret_access_key.to_s.length > 0
end
|
#applied_config ⇒ Object
Applied config is configuration values passed in context usually from the cli, but also in the unit tests
184
185
186
|
# File 'lib/datapimp/configuration.rb', line 184
def applied_config
@applied_config ||= {}
end
|
#apply_all(options = {}) ⇒ Object
118
119
120
|
# File 'lib/datapimp/configuration.rb', line 118
def apply_all(options={})
current.merge!(options)
end
|
#apply_config(hash = {}) ⇒ Object
149
150
151
152
|
# File 'lib/datapimp/configuration.rb', line 149
def apply_config(hash={})
applied_config.merge!(hash)
current.merge(applied_config)
end
|
#apply_config_from_path(path) ⇒ Object
154
155
156
157
158
159
|
# File 'lib/datapimp/configuration.rb', line 154
def apply_config_from_path(path)
path = Pathname(path)
parsed = JSON.parse(path.read) rescue {}
applied_config.merge!(parsed)
nil
end
|
#calculate_config(using_environment = true) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/datapimp/configuration.rb', line 131
def calculate_config(using_environment = true)
@current = defaults.merge(home_config.merge(cwd_config.merge(applied_config))).to_mash
if ENV['DATAPIMP_CONFIG_EXTRA'].to_s.length > 0
= Datapimp::Util.load_config_file(ENV['DATAPIMP_CONFIG_EXTRA'])
@current.merge!() if .is_a?(Hash)
end
(defaults.keys + home_config.keys + cwd_config.keys).uniq.each do |key|
upper = key.to_s.upcase
if ENV[upper]
@current[key] = ENV[upper]
end
end if using_environment
@current
end
|
#current(using_environment = true) ⇒ Object
36
37
38
|
# File 'lib/datapimp/configuration.rb', line 36
def current(using_environment = true)
@current ||= calculate_config(using_environment)
end
|
#cwd_config ⇒ Object
188
189
190
191
192
193
194
|
# File 'lib/datapimp/configuration.rb', line 188
def cwd_config
@cwd_config ||= begin
(cwd_config_path.exist? rescue false) ? JSON.parse(cwd_config_path.read) : {}
rescue
{}
end
end
|
#cwd_config_path ⇒ Object
218
219
220
|
# File 'lib/datapimp/configuration.rb', line 218
def cwd_config_path
@cwd_config_path || Pathname(Datapimp.pwd).join(manifest_filename)
end
|
#cwd_config_path=(value) ⇒ Object
214
215
216
|
# File 'lib/datapimp/configuration.rb', line 214
def cwd_config_path= value
@cwd_config_path = Pathname(value)
end
|
#defaults ⇒ Object
127
128
129
|
# File 'lib/datapimp/configuration.rb', line 127
def defaults
DefaultSettings.dup
end
|
#deploy_manifests_path ⇒ Object
66
67
68
69
70
|
# File 'lib/datapimp/configuration.rb', line 66
def deploy_manifests_path
Pathname(home_config_path.dirname).join("deploy-manifests").tap do |dir|
FileUtils.mkdir_p(dir) unless dir.exist?
end
end
|
#dnsimple_setup? ⇒ Boolean
76
77
78
|
# File 'lib/datapimp/configuration.rb', line 76
def dnsimple_setup?
dnsimple_api_token.to_s.length > 0 && dnsimple_username.to_s.length > 0
end
|
#dropbox_setup? ⇒ Boolean
80
81
82
|
# File 'lib/datapimp/configuration.rb', line 80
def dropbox_setup?
dropbox_app_key.to_s.length > 0 && dropbox_app_secret.to_s.length > 0
end
|
#get(setting) ⇒ Object
106
107
108
109
|
# File 'lib/datapimp/configuration.rb', line 106
def get(setting)
setting = setting.to_s.downcase
primary_config[setting]
end
|
#google_setup? ⇒ Boolean
84
85
86
|
# File 'lib/datapimp/configuration.rb', line 84
def google_setup?
google_client_secret.to_s.length > 0 && google_client_id.to_s.length > 0
end
|
#home_config ⇒ Object
196
197
198
199
200
201
202
203
204
|
# File 'lib/datapimp/configuration.rb', line 196
def home_config
initialize! unless home_config_path.exist?
@home_config ||= begin
(home_config_path.exist? rescue false) ? JSON.parse(home_config_path.read) : {}
rescue
{}
end
end
|
#home_config_path ⇒ Object
210
211
212
|
# File 'lib/datapimp/configuration.rb', line 210
def home_config_path
@home_config_path || Pathname(ENV['HOME']).join(".datapimp", manifest_filename)
end
|
#home_config_path=(value) ⇒ Object
206
207
208
|
# File 'lib/datapimp/configuration.rb', line 206
def home_config_path= value
@home_config_path = Pathname(value)
end
|
#initialize!(fresh = false) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/datapimp/configuration.rb', line 56
def initialize!(fresh=false)
return if home_config_path.exist? && !fresh
FileUtils.mkdir_p home_config_path.dirname
home_config_path.open("w+") do |fh|
fh.write(DefaultSettings.to_json)
end
end
|
#manifest_filename ⇒ Object
72
73
74
|
# File 'lib/datapimp/configuration.rb', line 72
def manifest_filename
"datapimp.json"
end
|
#primary_config ⇒ Object
102
103
104
|
# File 'lib/datapimp/configuration.rb', line 102
def primary_config
cwd_config_path.exist? ? cwd_config : home_config
end
|
#save! ⇒ Object
161
162
163
164
165
166
|
# File 'lib/datapimp/configuration.rb', line 161
def save!
save_home_config
save_cwd_config
@current = nil
true
end
|
#save_cwd_config ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/datapimp/configuration.rb', line 168
def save_cwd_config
return nil unless cwd_config_path.exist?
File.open(cwd_config_path, 'w+') do |fh|
fh.write JSON.generate(cwd_config.to_hash)
end
end
|
#save_home_config ⇒ Object
176
177
178
179
180
|
# File 'lib/datapimp/configuration.rb', line 176
def save_home_config
File.open(home_config_path, 'w+') do |fh|
fh.write JSON.generate(home_config.to_hash)
end
end
|
#set(setting, value, persist = true, options = {}) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/datapimp/configuration.rb', line 111
def set(setting, value, persist = true, options={})
setting = setting.to_s.downcase
primary_config[setting] = value
save! if persist == true
value
end
|
#show ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/datapimp/configuration.rb', line 92
def show
current.each do |p|
key, value = p
unless key == 'sites_directory'
puts "#{key}: #{ value.inspect }"
end
end
end
|
#unset(setting, persist = true) ⇒ Object
122
123
124
125
|
# File 'lib/datapimp/configuration.rb', line 122
def unset(setting, persist = true)
primary_config.delete(setting)
save! if persist == true
end
|