Module: GoodData::Mixin::MdObjectQuery
- Included in:
- GoodData::MdObject
- Defined in:
- lib/gooddata/mixins/md_object_query.rb
Constant Summary collapse
- ERROR_MESSAGE_NO_PROJECT =
'No :project specified'
Instance Method Summary collapse
-
#all(_options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project.
- #dependency(uri, key = nil, opts = { :client => GoodData.connection }) ⇒ Object
-
#dependency?(type, uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean
Checks for dependency.
-
#query(query_obj_type, klass, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to be called by individual classes in their all implementations.
-
#usedby(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object
(also: #used_by)
Returns which objects uses this MD resource.
- #usedby?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean (also: #used_by?)
-
#using(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object
Returns which objects this MD resource uses.
-
#using?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean
Checks if obj is using this MD resource.
Instance Method Details
#all(_options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project
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.
20 21 22 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 20 def all( = { :client => GoodData.connection, :project => GoodData.project }) fail NotImplementedError, 'Method should be implemented in subclass. Currently there is no way how to get all metadata objects on API.' end |
#dependency(uri, key = nil, opts = { :client => GoodData.connection }) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 63 def dependency(uri, key = nil, opts = { :client => GoodData.connection }) c = opts[:client] fail ArgumentError, 'No :client specified' if c.nil? result = c.get(uri)['entries'] if key.nil? result elsif key.respond_to?(:category) result = result.select { |item| item['category'] == key.category } else result = result.select { |item| item['category'] == key } end if opts[:full] result = result.map do |res| GoodData::MdObject[res['link'], :client => c, :project => opts[:project]] end end result end |
#dependency?(type, uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean
Checks for dependency
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 86 def dependency?(type, uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) uri = uri.respond_to?(:uri) ? uri.uri : uri objs = case type when :usedby usedby(uri, nil, opts) when :using using(uri, nil, opts) end target_uri = target_uri.respond_to?(:uri) ? target_uri.uri : target_uri objs.any? do |obj| obj['link'] == target_uri end end |
#query(query_obj_type, klass, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to be called by individual classes in their all implementations. It abstracts the way interacting with query resources. It either returns the array of hashes from query. If asked it also goes and brings the full objects. Due to performance reasons :full => false is the default. This will most likely change
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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 38 def query(query_obj_type, klass, = { :client => GoodData.connection, :project => GoodData.project }) client = [:client] fail ArgumentError, 'No :client specified' if client.nil? p = [:project] fail ArgumentError, ERROR_MESSAGE_NO_PROJECT if p.nil? project = GoodData::Project[p, ] fail ArgumentError, 'Wrong :project specified' if project.nil? offset = 0 page_limit = 50 Enumerator.new do |y| loop do result = client.get(project.md['objects'] + '/query', params: { category: query_obj_type, limit: page_limit, offset: offset }) result['objects']['items'].each do |item| y << (klass ? client.create(klass, item, project: project) : item) end break if result['objects']['paging']['count'] < page_limit offset += page_limit end end end |
#usedby(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object Also known as: used_by
Returns which objects uses this MD resource
102 103 104 105 106 107 108 109 110 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 102 def usedby(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) p = opts[:project] fail ArgumentError, ERROR_MESSAGE_NO_PROJECT if p.nil? project = GoodData::Project[p, opts] fail ArgumentError, ERROR_MESSAGE_NO_PROJECT if project.nil? dependency("#{project.md['usedby2']}/#{uri_obj_id(uri)}", key, opts) end |
#usedby?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean Also known as: used_by?
125 126 127 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 125 def usedby?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) dependency?(:usedby, uri, target_uri, opts) end |
#using(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object
Returns which objects this MD resource uses
115 116 117 118 119 120 121 122 123 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 115 def using(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) p = opts[:project] fail ArgumentError, ERROR_MESSAGE_NO_PROJECT if p.nil? project = GoodData::Project[p, opts] fail ArgumentError, ERROR_MESSAGE_NO_PROJECT if project.nil? dependency("#{project.md['using2']}/#{uri_obj_id(uri)}", key, opts) end |
#using?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Boolean
Checks if obj is using this MD resource
132 133 134 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 132 def using?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) dependency?(:using, uri, target_uri, opts) end |