Class: UU::OS::VUC::VisualUseCaseContext::ParametersDecorator

Inherits:
Lang::UniformHash
  • Object
show all
Defined in:
uu_os_vuc-server-3.6.2/lib/uu/os/vuc/visual_use_case_context.rb

Overview

Allows to work with view model attributes using visual use case context parameters.

Instance Method Summary (collapse)

Methods inherited from Lang::UniformHash

#default, #delete, #fetch, #has_key?, #has_value?, #include?, #key, #key?, #member?, #merge, #merge!, #replace, #store, #transform_key, #transform_value, #update, #value?, #values_at

Constructor Details

- (ParametersDecorator) initialize(ctx, parameters)

Constructor.

Parameters:



83
84
85
86
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/visual_use_case_context.rb', line 83

def initialize(ctx, parameters)
  merge!(parameters)
  @ctx = ctx
end

Instance Method Details

- (Object) [](key)

Returns value for the specified key from either view model attributes or this visual use case context parameters. The view model attributes are preferred if it contains a value with the specified key.

Parameters:

  • the (symbol or string)

    key whose associated value is to be returned



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/visual_use_case_context.rb', line 97

def [](key)
  result = nil
  isViewModelCreated = @ctx.instance_variable_defined?(:@view_model)

  key = transform_key(key)
  if (isViewModelCreated and key == reponse_view_attrs_key)
    result = @ctx.view
    logger.info("The #{key} attribute will be obtained from view model.") if logger.info_loggable?
  else
    if ( isViewModelCreated )
      result = @ctx.view[key]
      logger.info("The #{key} attribute is obtained from view model. Result: #{result}") if logger.info_loggable?
    end
    if ( result == nil )
      result = super(key)
      logger.info("The #{key} attribute is obtained from visual use case context parameters. Result: #{result}") if logger.info_loggable?
    end
  end
  
  return result
end

- (Object) []=(key, value)

Sets a parameter either to visual use case context parameters or to view model attributes if the key was set to the view attributes before. This means that setting an attribute to the view model hides parameter from the visual use case context with the same key.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/visual_use_case_context.rb', line 123

def []=(key, value)
  isViewModelCreated = @ctx.instance_variable_defined?(:@view_model)
  
  key = transform_key(key)
  if ( key == reponse_view_attrs_key )
    raise "Failed to set #{reponse_view_attrs_key}. The property is read-only."
  else
    if ( isViewModelCreated and @ctx.view.send(:is_attribute_defined?, key) )
      @ctx.view[key] = value
      logger.info("The #{key} attribute set to view model. The attribute value: #{value}") if logger.info_loggable?
    else
      super(key, value)
      logger.info("The #{key} attribute set to visual use case context parameters. The attribute value: #{value}") if logger.info_loggable?
    end
  end
end

- (Object) reponse_view_attrs_key

This key can be used for accessing view model attributes from visual use case context parameters.



89
90
91
# File 'uu_os_vuc-server-3.6.2/lib/uu/os/vuc/visual_use_case_context.rb', line 89

def reponse_view_attrs_key
  @@responseViewAttributes ||= transform_key(UU::OS::VUC::ViewModel::RESPONSE_VIEW_ATTRIBUTES)
end