Class: DataMapper::Adapters::BugzillaAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/dm-bugzilla-adapter.rb,
lib/dm-bugzilla-adapter/misc.rb,
lib/dm-bugzilla-adapter/read.rb,
lib/dm-bugzilla-adapter/create.rb,
lib/dm-bugzilla-adapter/delete.rb,
lib/dm-bugzilla-adapter/update.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ BugzillaAdapter

Returns a new instance of BugzillaAdapter.



63
64
65
66
67
68
# File 'lib/dm-bugzilla-adapter.rb', line 63

def initialize(name, options)
  super
  require 'uri'
  @uri = URI.parse(options[:url])
  @client = Bicho::Client.new(@uri)
end

Instance Method Details

#create(resources) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dm-bugzilla-adapter/create.rb', line 4

def create(resources)
  STDERR.puts "BugzillaAdapter::create"
  table_groups = group_resources_by_table(resources)
  table_groups.each do |table, resources|
    # make
    #  class User
    #    property :id, Serial
    #  end
    # work
    resources.each do |resource|
	initialize_serial(resource,
	  worksheet_record_cound(table)+1)
	post_resource_to_worksheet(resource,table)
    end
  end
  resources.size
end

#delete(collection) ⇒ Integer

Constructs and executes DELETE statement for given query

Parameters:

  • collection (Collection)

    collection of records to be deleted

Returns:

  • (Integer)

    the number of records deleted



14
15
16
17
18
19
20
# File 'lib/dm-bugzilla-adapter/delete.rb', line 14

def delete(collection)
  each_resource_with_edit_url(collection) do |resource, edit_url|
    connection.delete(edit_url, 'If-Match' => "*")
  end
  # return count
  collection.size
end

#get_bugs(ids) ⇒ Object

get Bugs by ids



71
72
73
# File 'lib/dm-bugzilla-adapter.rb', line 71

def get_bugs(ids)
  @client.get_bugs(*ids)
end

#named_query(name) ⇒ Object

run named query, return Array of bug ids



76
77
78
# File 'lib/dm-bugzilla-adapter.rb', line 76

def named_query(name)
  @client.get_bugs(name)
end

#read(query) ⇒ Array

Retrieves records for a particular model.

Parameters:

  • query (DataMapper::Query)

    The query used to locate the resources

Returns:

  • (Array)

    An array of hashes of all of the records for a particular model



16
17
18
19
20
21
22
23
24
# File 'lib/dm-bugzilla-adapter/read.rb', line 16

def read(query)
#      STDERR.puts "BugzillaAdapter::read"
#     fields = query.fields
#      STDERR.puts "fields #{fields.inspect}"
#      types  = fields.map { |property| property.primitive }
#      STDERR.puts "types #{types.inspect}"
  records = records_for(query)
#      query.filter_records(records)
end

#update(attributes, collection) ⇒ Integer

Constructs and executes UPDATE statement for given attributes and a query

Parameters:

  • attributes (Hash(Property => Object))

    hash of attribute values to set, keyed by Property

  • collection (Collection)

    collection of records to be updated

Returns:

  • (Integer)

    the number of records updated



16
17
18
19
20
21
22
# File 'lib/dm-bugzilla-adapter/update.rb', line 16

def update(attributes, collection)
  each_resource_with_edit_url(collection) do |resource, edit_url|
    put_updated_resource(edit_url, resource)
  end
  # return count
  collection.size
end