Module: GoodData::Bam::Utils
- Defined in:
- lib/utils/utils.rb
Constant Summary collapse
- PROJECT_GRAPHS_DIR =
"graphs"
- PROJECT_METADATA_DIR =
"metadata"
- PROJECT_DATA_DIR =
"data"
- PARAM_FILE =
'params.json'
Class Method Summary collapse
- .get_paths(base) ⇒ Object
- .get_user_params(base) ⇒ Object
- .merge_only_values(merge_onto, data, keys = []) ⇒ Object
- .render_template(template, params, options = {}) ⇒ Object
- .setup_basic_project(paths, options = {}) ⇒ Object
- .should_backup_to_s3?(params) ⇒ Boolean
Class Method Details
.get_paths(base) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/utils/utils.rb', line 10 def self.get_paths(base) base = Pathname(base) { :home_path => base, :graphs_path => base + PROJECT_GRAPHS_DIR, :metadata_path => base + PROJECT_METADATA_DIR, :data_path => base + PROJECT_DATA_DIR } end |
.get_user_params(base) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/utils/utils.rb', line 20 def self.get_user_params(base) base = Pathname(base) param_path = base + PARAM_FILE params = File.exist?(param_path) ? JSON.parse(File.read(param_path), :symbolize_names => true) : {} {:additional_params => {}}.merge(params) end |
.merge_only_values(merge_onto, data, keys = []) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/utils/utils.rb', line 64 def self.merge_only_values(merge_onto, data, keys=[]) filtered_data = data.inject({}) {|memo, k| memo[k.first] = k[1] unless k[0].blank?; memo} if keys.empty? merge_onto.merge(filtered_data) else merge_onto.merge(filtered_data.select {|key, val| keys.include?(key)}) end end |
.render_template(template, params, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/utils/utils.rb', line 27 def self.render_template(template, params, ={}) to_file = [:to_file] root = [:root] || GoodData::Bam::TEMPLATE_ROOT t = Pathname(template) output = Erubis::Eruby.new(File.read(root + t)).result(params) if to_file.nil? output else File.open(to_file, 'w') {|f| f.write(output)} end end |
.setup_basic_project(paths, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/utils/utils.rb', line 39 def self.setup_basic_project(paths, ={}) [:project_name, :project_pid].each do |param| fail "Project #{param} needs to be specified for project template to be generated" if [param].blank? end home = paths[:home_path] paths.values_at(:home_path, :graphs_path, :metadata_path, :data_path).each do |dir| FileUtils::mkdir_p dir end File.open(home + 'params.prm', 'w') do |f| f << "TRASH=0\n" end Utils::render_template("project.erb", , :to_file => home + '.project') Utils::render_template("workspace.prm.erb", , :to_file => home + 'workspace.prm') end |
.should_backup_to_s3?(params) ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/utils/utils.rb', line 56 def self.should_backup_to_s3?(params) keys = [:S3_SECRET_ACCESS_KEY, :S3_ACCESS_KEY_ID, :S3_BUCKETNAME] if keys.any? {|key| params[:additional_params].has_key?(key) && params[:additional_params][key].blank?} fail "You still have unfilled keys :S3_SECRET_ACCESS_KEY or :S3_ACCESS_KEY_ID or :S3_BUCKETNAME. Fill them in or delete them explicitely. If you do that your data will not be backed up." end keys.all? {|key| !params[:additional_params][key].blank?} end |