diff options
author | Luke Kanies <luke@madstop.com> | 2009-05-06 15:22:43 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-06-06 19:57:58 +1000 |
commit | f059c518411f2f12bbe9108094b12f9bfc13e080 (patch) | |
tree | 8c06764c17a6ebe6c8b659201d5b11e3870ea971 /lib/puppet | |
parent | 7f322b315a7890f1b3cee035d023f09814cc6075 (diff) | |
download | puppet-f059c518411f2f12bbe9108094b12f9bfc13e080.tar.gz puppet-f059c518411f2f12bbe9108094b12f9bfc13e080.tar.xz puppet-f059c518411f2f12bbe9108094b12f9bfc13e080.zip |
Adding JSON support to Puppet::Relationship
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/relationship.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb index 97c84ac0e..4c44adba7 100644 --- a/lib/puppet/relationship.rb +++ b/lib/puppet/relationship.rb @@ -14,6 +14,21 @@ class Puppet::Relationship attr_reader :event + def self.from_json(json) + source = json["source"] + target = json["target"] + + args = {} + if event = json["event"] + args[:event] = event + end + if callback = json["callback"] + args[:callback] = callback + end + + new(source, target, args) + end + def event=(event) if event != :NONE and ! callback raise ArgumentError, "You must pass a callback for non-NONE events" @@ -55,8 +70,24 @@ class Puppet::Relationship "%s => %s" % [source, target] end + def to_json(*args) + data = { + 'source' => source.to_s, + 'target' => target.to_s + } + + ["event", "callback"].each do |attr| + next unless value = send(attr) + data[attr] = value + end + + { + 'json_class' => self.class.to_s, + 'data' => data + }.to_json(*args) + end + def to_s ref end end - |