lib/gooddata/models/metadata/metric.rb in gooddata-0.6.24 vs lib/gooddata/models/metadata/metric.rb in gooddata-0.6.25
- old
+ new
@@ -10,17 +10,12 @@
require_relative 'metadata'
module GoodData
# Metric representation
class Metric < MdObject
- include GoodData::Mixin::Lockable
+ include Mixin::Lockable
- alias_method :to_hash, :json
-
- include GoodData::Mixin::RestResource
- root_key :metric
-
class << self
# Method intended to get all objects of that type in a specified project
#
# @param options [Hash] the options hash
# @option options [Boolean] :full if passed true the subclass can decide to pull in full objects. This is desirable from the usability POV but unfortunately has negative impact on performance so it is not the default
@@ -32,19 +27,12 @@
def xcreate(metric, options = { :client => GoodData.connection, :project => GoodData.project })
create(metric, { extended_notation: true }.merge(options))
end
def create(metric, options = { :client => GoodData.connection, :project => GoodData.project })
- client = options[:client]
- fail ArgumentError, 'No :client specified' if client.nil?
+ client, project = GoodData.get_client_and_project(options)
- p = options[:project]
- fail ArgumentError, 'No :project specified' if p.nil?
-
- project = GoodData::Project[p, options]
- fail ArgumentError, 'Wrong :project specified' if project.nil?
-
if metric.is_a?(String)
expression = metric || options[:expression]
extended_notation = options[:extended_notation] || false
title = options[:title]
summary = options[:summary]
@@ -117,19 +105,12 @@
end
m.execute
end
def xexecute(expression, opts = { :client => GoodData.connection, :project => GoodData.project })
- client = opts[:client]
- fail ArgumentError, 'No :client specified' if client.nil?
+ GoodData.get_client_and_project(opts)
- p = opts[:project]
- fail ArgumentError, 'No :project specified' if p.nil?
-
- project = GoodData::Project[p, opts]
- fail ArgumentError, 'Wrong :project specified' if project.nil?
-
execute(expression, opts.merge(:extended_notation => true))
end
end
def execute
@@ -173,30 +154,18 @@
def contain_value?(label, value)
uri = label.find_value_uri(value)
contain?(uri)
end
- # Method used for replacing objects like Attribute, Fact or Metric.
- # @param [GoodData::MdObject] what Object that should be replaced
- # @param [GoodData::MdObject] for_what Object it is replaced with
+ # Method used for replacing values in their state according to mapping. Can be used to replace any values but it is typically used to replace the URIs. Returns a new object of the same type.
+ #
+ # @param [Array<Array>]Mapping specifying what should be exchanged for what. As mapping should be used output of GoodData::Helpers.prepare_mapping.
# @return [GoodData::Metric]
- def replace(what, for_what = nil)
- pairs = if what.is_a?(Hash)
- whats = what.keys
- to_whats = what.values
- whats.zip(to_whats)
- elsif what.is_a?(Array) && for_what.is_a?(Array)
- whats.zip(to_whats)
- else
- [[what, for_what]]
- end
-
- pairs.each do |a, b|
- uri_what = a.respond_to?(:uri) ? a.uri : a
- uri_for_what = b.respond_to?(:uri) ? b.uri : b
- self.expression = expression.gsub("[#{uri_what}]", "[#{uri_for_what}]")
- end
- self
+ def replace(mapping)
+ x = GoodData::MdObject.replace_quoted(self, mapping)
+ x = GoodData::MdObject.replace_bracketed(x, mapping)
+ vals = GoodData::MdObject.find_replaceable_values(x, mapping)
+ GoodData::MdObject.replace_bracketed(x, vals)
end
# Method used for replacing attribute element values. Looks up certain value of a label in the MAQL expression and exchanges it for a different value of the same label.
# @param [GoodData::Label] label Label through which the value and for_value are resolved
# @param [String] value value that is going to be replaced