1f7cdcda4ac8f1ff3cdfb0ac71b627634dae9dfc
[packages/precise/mcollective.git] / lib / mcollective / ddl / dataddl.rb
1 module MCollective
2   module DDL
3     # A DDL file for the data query plugins.
4     #
5     # Query plugins can today take only one input by convention in the DDL that
6     # is called :query, otherwise the input is identical to the standard input.
7     #
8     # metadata    :name        => "Agent",
9     #             :description => "Meta data about installed MColletive Agents",
10     #             :author      => "R.I.Pienaar <rip@devco.net>",
11     #             :license     => "ASL 2.0",
12     #             :version     => "1.0",
13     #             :url         => "http://marionette-collective.org/",
14     #             :timeout     => 1
15     #
16     # dataquery :description => "Agent Meta Data" do
17     #     input :query,
18     #           :prompt => "Agent Name",
19     #           :description => "Valid agent name",
20     #           :type => :string,
21     #           :validation => /^[\w\_]+$/,
22     #           :maxlength => 20
23     #
24     #     [:license, :timeout, :description, :url, :version, :author].each do |item|
25     #       output item,
26     #              :description => "Agent #{item}",
27     #              :display_as => item.to_s.capitalize
28     #     end
29     # end
30     class DataDDL<Base
31       def dataquery(input, &block)
32         raise "Data queries need a :description" unless input.include?(:description)
33         raise "Data queries can only have one definition" if @entities[:data]
34
35         @entities[:data]  = {:description => input[:description],
36                              :input => {},
37                              :output => {}}
38
39         @current_entity = :data
40         block.call if block_given?
41         @current_entity = nil
42       end
43
44       def input(argument, properties)
45         raise "The only valid input name for a data query is 'query'" if argument != :query
46
47         super
48       end
49
50       # Returns the interface for the data query
51       def dataquery_interface
52         @entities[:data] || {}
53       end
54     end
55   end
56 end