Class: Dcmgr::Cli::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/dcmgr/cli/tag.rb

Constant Summary collapse

M =
Dcmgr::Models

Instance Method Summary collapse

Instance Method Details

#addObject



14
15
16
17
18
19
# File 'lib/dcmgr/cli/tag.rb', line 14

def add
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
  Error.raise("Invalid type_id: '#{options[:type_id]}'. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'.",100) unless Dcmgr::Tags::KEY_MAP.member? options[:type_id]
  
  puts super(M::Tag,options)
end

#del(uuid) ⇒ Object



58
59
60
# File 'lib/dcmgr/cli/tag.rb', line 58

def del(uuid)
  super(M::Tag,uuid)
end

#map(uuid, object_uuid) ⇒ Object

method_option :object_id, :type => :string, :desc => “The canonical UUID for the object to map this tag to.”, :required => true



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dcmgr/cli/tag.rb', line 70

def map(uuid, object_uuid)
  #Quick hack to get all models in Dcmgr::Models loaded in Taggable.uuid_prefix_collection
  #This is so the Taggable.find method can be used to determine the Model class based on canonical uuid
  M.constants.each {|c| eval("M::#{c}")}
  
  object = M::Taggable.find(object_uuid)

  UnknownUUIDError.raise(uuid) if M::Tag[uuid].nil?
  UnknownUUIDError.raise(object_uuid) if object.nil?
  Error.raise("Tag '#{uuid}' can not be mapped to a '#{object.class}'.",100) unless M::Tag[uuid].accept_mapping?(object)
  
  M::TagMapping.create(
    :tag_id => M::Tag[uuid].id,
    :uuid   => object.canonical_uuid
  )
end

#modify(uuid) ⇒ Object



26
27
28
29
30
# File 'lib/dcmgr/cli/tag.rb', line 26

def modify(uuid)
  UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
  Error.raise("Invalid type_id: '#{options[:type_id]}'. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'.",100) unless options[:type_id].nil? || Dcmgr::Tags::KEY_MAP.member?(options[:type_id])
  super(M::Tag,uuid,options)
end

#show(uuid = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dcmgr/cli/tag.rb', line 33

def show(uuid=nil)
  if uuid
    tag = M::Tag[uuid] || UnknownUUIDError.raise(uuid)
    puts ERB.new(<<__END, nil, '-').result(binding)
Tag UUID:
  <%= tag.canonical_uuid %>
Account id:
  <%= tag.account_id %>
Name:
  <%= tag.name %>
Type id:
  <%= tag.type_id %>
Attributes:
  <%= tag.attributes %>
__END
  else
    puts ERB.new(<<__END, nil, '-').result(binding)
<%- M::Tag.each { |row| -%>
<%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.type_id %>\t<%= row.name%>
<%- } -%>
__END
  end
end