Method: GoodData::MdObject.replace
- Defined in:
- lib/gooddata/models/metadata.rb
.replace(obj, mapping, &block) ⇒ GoodData::MdObject
Helper method used for replacing objects like Attribute, Fact or Metric. It takes the object. Scans its JSON representation yields for a client to perform replacement for each mapping pair and returns a new one with object of the same type as obj.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gooddata/models/metadata.rb', line 70 def replace(obj, mapping, &block) json = mapping.reduce(obj.to_json) do |a, e| obj_a, obj_b = e uri_what = obj_a.respond_to?(:uri) ? obj_a.uri : obj_a uri_for_what = obj_b.respond_to?(:uri) ? obj_b.uri : obj_b block.call(a, uri_what, uri_for_what) end client = obj.client client.create(obj.class, MultiJson.load(json), :project => obj.project) end |