Module: GoodData::Bam::Project
- Defined in:
- lib/base/project.rb
Class Method Summary collapse
- .build_project(home = '.', options = {}) ⇒ Object
- .create(project) ⇒ Object
- .find_by(project, what, by_what, name) ⇒ Object
- .find_graph_by_path(project, path) ⇒ Object
- .find_sink_by_id(project, name) ⇒ Object
- .find_sink_by_name(project, name) ⇒ Object
- .find_tap_by_id(project, name) ⇒ Object
- .find_tap_by_name(project, name) ⇒ Object
- .load_flows_definitions(project, path) ⇒ Object
- .load_sinks(project, path) ⇒ Object
- .load_taps(project, path) ⇒ Object
- .mark_deleted_taps(project, options) ⇒ Object
- .set_graph_repos(project, repos = []) ⇒ Object
Class Method Details
.build_project(home = '.', options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/base/project.rb', line 102 def self.build_project(home='.', ={}) home = Pathname(home) project = Project.create({}) paths = [:graph_repos] || [] p = Project.load_taps(project, home + 'taps') p = Project.load_sinks(p, home + 'sinks') p = Project.set_graph_repos(p, paths) p = Project.mark_deleted_taps(p, ) p = Project.load_flows_definitions(p, home + "flows") p = Compiler.compile_dsl(p) end |
.create(project) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/base/project.rb', line 5 def self.create(project) { :flows => [], :flows_definitions => [], :taps => [], :sinks => [] }.merge(project).merge({:type => :project}) end |
.find_by(project, what, by_what, name) ⇒ Object
14 15 16 |
# File 'lib/base/project.rb', line 14 def self.find_by(project, what, by_what, name) project[what].detect {|item| item[by_what] == name} end |
.find_graph_by_path(project, path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/base/project.rb', line 34 def self.find_graph_by_path(project, path) found = project[:graph_repos].reduce([]) do |acc, repo| if Bam::Repository.find(repo, path) acc.concat([Bam::Repository.find(repo, path)]) else acc end end found.first end |
.find_sink_by_id(project, name) ⇒ Object
26 27 28 |
# File 'lib/base/project.rb', line 26 def self.find_sink_by_id(project, name) Project.find_by(project, :sinks, :id, name) end |
.find_sink_by_name(project, name) ⇒ Object
30 31 32 |
# File 'lib/base/project.rb', line 30 def self.find_sink_by_name(project, name) Project.find_by(project, :sinks, :name, name) end |
.find_tap_by_id(project, name) ⇒ Object
18 19 20 |
# File 'lib/base/project.rb', line 18 def self.find_tap_by_id(project, name) Project.find_by(project, :taps, :id, name) end |
.find_tap_by_name(project, name) ⇒ Object
22 23 24 |
# File 'lib/base/project.rb', line 22 def self.find_tap_by_name(project, name) Project.find_by(project, :taps, :name, name) end |
.load_flows_definitions(project, path) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/base/project.rb', line 94 def self.load_flows_definitions(project, path) p = Pathname(path) flows = Pathname.glob(p + "*.rb").map do |p| GoodData::Bam::DSL.class_eval(File.read p).to_hash end Project.create(project.merge({:flows_definitions => flows})) end |
.load_sinks(project, path) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/base/project.rb', line 76 def self.load_sinks(project, path) p = Pathname(path) sinks = Pathname.glob(p + "*.json").map do |p| Sink.create(JSON.parse(File.read(p), :symbolize_names => true)) end Project.create(project.merge({:sinks => sinks})) end |
.load_taps(project, path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/base/project.rb', line 45 def self.load_taps(project, path) p = Pathname(path) taps = Pathname.glob(p + "*.json").map do |p| Tap.create(JSON.parse(File.read(p), :symbolize_names => true)) end groups = taps.group_by {|t| t[:id]}.map {|k,v| [k, v.count]} bad_groups = groups.find_all do |group| group[1] > 1 end unless bad_groups.empty? fail "There are several taps that have the same id. Namely #{bad_groups.map {|g| g.first}.join(', ')}. The ids of taps need to be unique." end Project.create(project.merge({:taps => taps.map {|tap| Tap.create(tap)}})) end |
.mark_deleted_taps(project, options) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/base/project.rb', line 84 def self.mark_deleted_taps(project, ) taps = project[:taps] enriched_taps = if taps.any? {|t| t[:source] == :salesforce} Taps.get_deleted_records_info(taps, GoodData::Bam::Commands.get_sf_client()) else taps.map {|t| t.merge({:has_deleted_records => false})} end Project.create(project.merge({:taps => enriched_taps})) end |
.set_graph_repos(project, repos = []) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/base/project.rb', line 62 def self.set_graph_repos(project, repos=[]) # paths = paths.map {|p| Pathname(p)} # graphs = paths.reduce([]) do |acc, path| # Pathname.glob(path + "*.grf").map do |graph_path| # acc.concat([Graph.create({ # :path => graph_path # })]) # end # acc # end Project.create(project.merge({:graph_repos => repos})) end |