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: '',
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
47
48
49
50
51
52
53
|
# File 'lib/datapimp/configuration.rb', line 47
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
39
40
41
42
43
44
45
|
# File 'lib/datapimp/configuration.rb', line 39
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
87
88
89
|
# File 'lib/datapimp/configuration.rb', line 87
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
183
184
185
|
# File 'lib/datapimp/configuration.rb', line 183
def applied_config
@applied_config ||= {}
end
|
#apply_all(options = {}) ⇒ Object
117
118
119
|
# File 'lib/datapimp/configuration.rb', line 117
def apply_all(options={})
current.merge!(options)
end
|
#apply_config(hash = {}) ⇒ Object
148
149
150
151
|
# File 'lib/datapimp/configuration.rb', line 148
def apply_config(hash={})
applied_config.merge!(hash)
current.merge(applied_config)
end
|
#apply_config_from_path(path) ⇒ Object
153
154
155
156
157
158
|
# File 'lib/datapimp/configuration.rb', line 153
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/datapimp/configuration.rb', line 130
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
35
36
37
|
# File 'lib/datapimp/configuration.rb', line 35
def current(using_environment = true)
@current ||= calculate_config(using_environment)
end
|
#cwd_config ⇒ Object
187
188
189
190
191
192
193
|
# File 'lib/datapimp/configuration.rb', line 187
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
217
218
219
|
# File 'lib/datapimp/configuration.rb', line 217
def cwd_config_path
@cwd_config_path || Pathname(Datapimp.pwd).join(manifest_filename)
end
|
#cwd_config_path=(value) ⇒ Object
213
214
215
|
# File 'lib/datapimp/configuration.rb', line 213
def cwd_config_path= value
@cwd_config_path = Pathname(value)
end
|
#defaults ⇒ Object
126
127
128
|
# File 'lib/datapimp/configuration.rb', line 126
def defaults
DefaultSettings.dup
end
|
#deploy_manifests_path ⇒ Object
65
66
67
68
69
|
# File 'lib/datapimp/configuration.rb', line 65
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
75
76
77
|
# File 'lib/datapimp/configuration.rb', line 75
def dnsimple_setup?
dnsimple_api_token.to_s.length > 0 && dnsimple_username.to_s.length > 0
end
|
#dropbox_setup? ⇒ Boolean
79
80
81
|
# File 'lib/datapimp/configuration.rb', line 79
def dropbox_setup?
dropbox_app_key.to_s.length > 0 && dropbox_app_secret.to_s.length > 0
end
|
#get(setting) ⇒ Object
105
106
107
108
|
# File 'lib/datapimp/configuration.rb', line 105
def get(setting)
setting = setting.to_s.downcase
primary_config[setting]
end
|
#google_setup? ⇒ Boolean
83
84
85
|
# File 'lib/datapimp/configuration.rb', line 83
def google_setup?
google_client_secret.to_s.length > 0 && google_client_id.to_s.length > 0
end
|
#home_config ⇒ Object
195
196
197
198
199
200
201
202
203
|
# File 'lib/datapimp/configuration.rb', line 195
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
209
210
211
|
# File 'lib/datapimp/configuration.rb', line 209
def home_config_path
@home_config_path || Pathname(ENV['HOME']).join(".datapimp", manifest_filename)
end
|
#home_config_path=(value) ⇒ Object
205
206
207
|
# File 'lib/datapimp/configuration.rb', line 205
def home_config_path= value
@home_config_path = Pathname(value)
end
|
#initialize!(fresh = false) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/datapimp/configuration.rb', line 55
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
71
72
73
|
# File 'lib/datapimp/configuration.rb', line 71
def manifest_filename
"datapimp.json"
end
|
#primary_config ⇒ Object
101
102
103
|
# File 'lib/datapimp/configuration.rb', line 101
def primary_config
cwd_config_path.exist? ? cwd_config : home_config
end
|
#save! ⇒ Object
160
161
162
163
164
165
|
# File 'lib/datapimp/configuration.rb', line 160
def save!
save_home_config
save_cwd_config
@current = nil
true
end
|
#save_cwd_config ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/datapimp/configuration.rb', line 167
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
175
176
177
178
179
|
# File 'lib/datapimp/configuration.rb', line 175
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
110
111
112
113
114
115
|
# File 'lib/datapimp/configuration.rb', line 110
def set(setting, value, persist = true, options={})
setting = setting.to_s.downcase
primary_config[setting] = value
save! if persist == true
value
end
|
#show ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/datapimp/configuration.rb', line 91
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
121
122
123
124
|
# File 'lib/datapimp/configuration.rb', line 121
def unset(setting, persist = true)
primary_config.delete(setting)
save! if persist == true
end
|