Module: GoodData::Mixin::MdFinders

Included in:
GoodData::MdObject
Defined in:
lib/gooddata/mixins/md_finders.rb

Instance Method Summary collapse

Instance Method Details

#find_by_identifier(identifier, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject>

Finds a specific type of the object by identifier. Returns all matches. Returns full object.

Parameters:

  • title (String)

    identifier that has to match exactly

  • title (Regexp)

    regular expression that has to match

Returns:



30
31
32
33
34
35
36
37
38
# File 'lib/gooddata/mixins/md_finders.rb', line 30

def find_by_identifier(identifier, options = { :client => GoodData.connection, :project => GoodData.project })
  all = self[:all, options]
  items = if identifier.is_a?(Regexp)
            all.select { |r| r.title =~ identifier }
          else
            all.select { |r| r.title == identifier }
          end
  items.pmap { |item| self[item.uri, options] unless item.nil? }
end

#find_by_tag(tags, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/gooddata/mixins/md_finders.rb', line 40

def find_by_tag(tags, opts = { :client => GoodData.connection, :project => GoodData.project })
  client, project = GoodData.get_client_and_project(opts)
  tags = tags.split(',').map(&:strip) unless tags.is_a?(Array)

  self[:all, client: client, project: project]
    .select { |r| (r.tag_set & tags).any? }
end

#find_by_title(title, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject>

Finds a specific type of the object by title. Returns all matches. Returns full object.

Parameters:

  • title (String)

    title that has to match exactly

  • title (Regexp)

    regular expression that has to match

Returns:



68
69
70
71
72
73
74
75
76
# File 'lib/gooddata/mixins/md_finders.rb', line 68

def find_by_title(title, options = { :client => GoodData.connection, :project => GoodData.project })
  all = self[:all, options]
  items = if title.is_a?(Regexp)
            all.select { |r| r.title =~ title }
          else
            all.select { |r| r.title == title }
          end
  items.pmap { |item| self[item.uri, options] unless item.nil? }
end

#find_first_by_identifier(identifier, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject>

Finds a specific type of the object by identifier. Returns first match. Returns full object.

Parameters:

  • title (String)

    identifier that has to match exactly

  • title (Regexp)

    regular expression that has to match

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/gooddata/mixins/md_finders.rb', line 15

def find_first_by_identifier(identifier, options = { :client => GoodData.connection, :project => GoodData.project })
  all = self[:all, options.merge(full: false)]
  item = if identifier.is_a?(Regexp)
           all.find { |r| r.identifier =~ identifier }
         else
           all.find { |r| r.identifier == identifier }
         end
  self[item.uri, options] unless item.nil?
end

#find_first_by_title(title, options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject>

Finds a specific type of the object by title. Returns first match. Returns full object.

Parameters:

  • title (String)

    title that has to match exactly

  • title (Regexp)

    regular expression that has to match

Returns:



53
54
55
56
57
58
59
60
61
# File 'lib/gooddata/mixins/md_finders.rb', line 53

def find_first_by_title(title, options = { :client => GoodData.connection, :project => GoodData.project })
  all = self[:all, options]
  item = if title.is_a?(Regexp)
           all.find { |r| r.title =~ title }
         else
           all.find { |r| r.title == title }
         end
  self[item.uri, options] unless item.nil?
end