Sha256: 8f7b44d7ea4afec47fb6a4c4107c1c26cd5d2b4c2d028eb99dfa332a095ae41b

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 KB

Contents

module Reactor
  module Cm
    class Attribute
      def self.exists?(name)
        begin
          Attribute.new.send(:get, name).ok?
        rescue StandardError
          false
        end
      end

      def self.instance(name)
        attr = Attribute.new
        attr.instance_variable_set("@name", name)
        attr
      end

      def self.get(name)
        attr = Attribute.new
        attr.send(:get, name)
        attr
      end

      def self.create(name, type)
        attr = Attribute.new
        attr.send(:create, name, type)
        attr
      end

      def set(key, value)
        @params[key.to_sym] = value
      end

      def save!
        request = XmlRequest.prepare do |xml|
          xml.where_key_tag!(base_name, "name", @name)
          xml.set_tag!(base_name) do
            @params.each do |key, value|
              xml.value_tag!(key.to_s, value)
            end
          end
        end
        request.execute!
      end

      def delete!
        request = XmlRequest.prepare do |xml|
          xml.where_key_tag!(base_name, "name", @name)
          xml.tag!("#{base_name}-delete")
        end
        request.execute!
      end

      protected

      def base_name
        "attribute"
      end

      def initialize
        @params = {}
      end

      def get(name)
        request = XmlRequest.prepare do |xml|
          xml.where_key_tag!(base_name, "name", name)
          xml.get_key_tag!(base_name, "name")
        end
        response = request.execute!
        @name = name
        response
      end

      def create(name, type)
        request = XmlRequest.prepare do |xml|
          xml.create_tag!(base_name) do
            xml.tag!("name") do
              xml.text!(name)
            end
            xml.tag!("type") do
              xml.text!(type)
            end
          end
        end
        response = request.execute!
        @name = name
        response
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
infopark_reactor-1.29.1 lib/reactor/cm/attribute.rb
infopark_reactor-1.29.0 lib/reactor/cm/attribute.rb
infopark_reactor-1.28.0 lib/reactor/cm/attribute.rb
infopark_reactor-1.27.0.rc10 lib/reactor/cm/attribute.rb
infopark_reactor-1.27.0.rc9 lib/reactor/cm/attribute.rb
infopark_reactor-1.27.0.rc8 lib/reactor/cm/attribute.rb
infopark_reactor-1.27.0.rc7 lib/reactor/cm/attribute.rb
infopark_reactor-1.27.0.rc4 lib/reactor/cm/attribute.rb