Module: GoodData::Mixin::MdObjectIndexer
- Included in:
- GoodData::MdObject
- Defined in:
- lib/gooddata/mixins/md_object_indexer.rb
Constant Summary collapse
- MD_OBJ_CTG =
'obj'
Instance Method Summary collapse
-
#[](id, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ MdObject, Array
(also: #get_by_id)
Returns either list of objects or a specific object.
Instance Method Details
#[](id, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ MdObject, Array Also known as: get_by_id
Returns either list of objects or a specific object. This method is reimplemented in subclasses to leverage specific implementation for specific type of objects. Options is used in subclasses specifically to provide shorthand for getting a full objects after getting a list of hashes from query resource
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gooddata/mixins/md_object_indexer.rb', line 18 def [](id, = { :client => GoodData.connection, :project => GoodData.project }) client, project = GoodData.get_client_and_project() fail "You have to provide an \"id\" to be searched for." unless id fail(NoProjectError, 'Connect to a project before searching for an object') unless project return all() if id == :all return id if id.is_a?(MdObject) uri = if id.is_a?(Integer) || id =~ /^\d+$/ "#{project.md[MD_OBJ_CTG]}/#{id}" elsif id !~ %r{/} identifier_to_uri , id elsif id =~ %r{^/} id else fail 'Unexpected object id format: expected numeric ID, identifier with no slashes or an URI starting with a slash' end # new(GoodData.get uri) unless uri.nil? if uri # rubocop:disable Style/GuardClause raw = client.get(uri) md_class = self case raw.keys.first when 'attribute' md_class = GoodData::Attribute when 'metric' md_class = GoodData::Metric when 'projectDashboard' md_class = GoodData::Dashboard when 'report' md_class = GoodData::Report when 'attributeDisplayForm' md_class = GoodData::Label when 'reportDefinition' md_class = GoodData::ReportDefinition when 'dataSet' md_class = GoodData::Dataset else md_class = self end client.create(md_class, raw, client: client, project: project) end end |