Sha256: a2bbe1fa0361142e56f4fc790398761c370da76c661826f114eb411600b52646

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

require 'rhcp/command_param'

module RHCP
  
  module Client
    
      # This is a proxy representing a remote CommandParam - see
      # RHCP::CommandParam for details
      class CommandParamStub < RHCP::CommandParam
        
        # the block that should be executed when +get_lookup_values+ is called
        # on this CommandParamStub
        attr_accessor :get_lookup_values_block
        
        # when constructing a CommandParamStub, the +:lookup_method+ option is 
        # set to +remote_get_lookup_values+ so that a method can be injected
        # from outside that will retrieve the lookup values (using the
        # +get_lookup_values_block+ property).
        def initialize(name, description, options)
          # we don't need to stub anything if the method does not have lookup values
          if (options[:has_lookup_values])
            options[:lookup_method] = self.method(:remote_get_lookup_values)
          end
          super(name, description, options)
        end
        
        def self.reconstruct_from_json(json_data)
          object = json_data.instance_of?(Hash) ? json_data : JSON.parse(json_data)
          args = object.values_at('name', 'description')
          args << {
            :allows_multiple_values => object['allows_multiple_values'],
            :has_lookup_values => object['has_lookup_values'],
            :is_default_param => object['is_default_param'],
            :mandatory => object['mandatory']
          }
          self.new(*args)
        end
        
        def remote_get_lookup_values(partial_value = "")
          @get_lookup_values_block.call(partial_value)
        end
        
      end      

  end
  
end

 


Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rhcp-0.1.4 lib/rhcp/client/command_param_stub.rb
rhcp-0.1.5 lib/rhcp/client/command_param_stub.rb
rhcp-0.1.6 lib/rhcp/client/command_param_stub.rb
rhcp-0.1.8 lib/rhcp/client/command_param_stub.rb
rhcp-0.1.9 lib/rhcp/client/command_param_stub.rb
rhcp-0.1.7 lib/rhcp/client/command_param_stub.rb