Module: GoodData::Mixin::MdObjectQuery
- Included in:
- GoodData::MdObject
- Defined in:
- lib/gooddata/mixins/md_object_query.rb
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
15 16 17 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 15 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 54 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 77 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 30 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, 'No :project specified' 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
93 94 95 96 97 98 99 100 101 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 93 def usedby(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) p = opts[:project] fail ArgumentError, 'No :project specified' if p.nil? project = GoodData::Project[p, opts] fail ArgumentError, 'No :project specified' 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?
116 117 118 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 116 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
106 107 108 109 110 111 112 113 114 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 106 def using(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project }) p = opts[:project] fail ArgumentError, 'No :project specified' if p.nil? project = GoodData::Project[p, opts] fail ArgumentError, 'No :project specified' 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
123 124 125 |
# File 'lib/gooddata/mixins/md_object_query.rb', line 123 def using?(uri, target_uri, opts = { :client => GoodData.connection, :project => GoodData.project }) dependency?(:using, uri, target_uri, opts) end |