Class: Lorj::Model
Overview
Model Object
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#meta_data ⇒ Object
Returns the value of attribute meta_data.
-
#meta_obj ⇒ Object
Returns the value of attribute meta_obj.
-
#meta_predefined_values ⇒ Object
Returns the value of attribute meta_predefined_values.
-
#query_auto_map ⇒ Object
Returns the value of attribute query_auto_map.
Instance Method Summary collapse
- #[](option) ⇒ Object
- #[]=(option, value) ⇒ Object
-
#attribute_context(options = nil) ⇒ Object
Current Attribute identifier.
- #clear_heap ⇒ Object
-
#data_context(data = nil) ⇒ Object
Internal Current Data identifier.
- #heap(value = nil) ⇒ Object
-
#initialize ⇒ Model
constructor
Model initialisation.
- #needs_optional(value = nil) ⇒ Object
- #needs_setup(value = nil) ⇒ Object
-
#object_context(options = nil) ⇒ Object
Object Context identifier (get/set) parameters: - options: Hash.
-
#options(options = nil) ⇒ Object
Model options (get/set) Uses Hash merge to set model options.
-
#process_context(process = nil) ⇒ Object
Internal Current Process identifier parameters: (Hash) -
:process
: optional.
Constructor Details
#initialize ⇒ Model
Model initialisation
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/core/core_model.rb', line 29 def initialize ################################################### # Class management Section ################################################### # Meta Object declaration structure # <Object> # :query_mapping List of keypath mapped. # <keypath> = <keypath mapped> # :lambdas: # :create_e: function to call at 'Create' task # :delete_e: function to call at 'Delete' task # :update_e: function to call at 'Update' task # :get_e: function to call at 'Get' task # :query_e: function to call at 'Query' task # :value_mapping: Define list of Object's key values mapping. # <keypath> key value mapping lists # <value> = <map> Define the value mapping. # :returns # <keypath> key value to extract from controller object. # :params: Defines CloudData (:data) or object (:CloudObj) # needs by the <Object> # :keys: Contains keys in a tree of hash. # <keypath>: String. One element (string with : and /) of # :list defining the key # :type: :data or :CloudObj # :for: Array of events which requires the data or # CloudObj to work. # :mapping: To automatically create a provider hash data # mapped (hdata). # :required: True if this parameter is required. # :extract_from: Array. Build the keypath value from another # params value. # Ex: This example will extract :id from # :security_groups object # :extract_from => [:security_groups, :id] # @meta_obj = {} # meta data are defined in defaults.yaml and loaded in Lorj::Default class # definition. # Cloud provider can redefine ForjData defaults and add some extra # parameters. # To get Application defaults, read defaults.yaml, under :sections: # Those values can be updated by the controller with define_data # <Section>: # <Data>: Required. Symbol/String. default: nil # => Data name. This symbol must be unique, across # sections. # :desc: Required. String. default: nil # => Description # :explanation: |- Print a multiline explanation before ask the key # value. # ERB template enable. To get config data, # type <%= config[...] %> # :readonly: Optional. true/false. Default: false # => oForjConfig.set() will fail if readonly is # true. It can be set, only thanks to: # - oForjConfig.setup() # or using private # - oForjConfig._set() # :account_exclusive: Optional. true/false. Default: false # => Only oConfig.account_get/set() can handle the # value # oConfig.set/get cannot. # :account: Optional. default: False # => setup will configure the account with this # <Data> # :ask_sort: Number which represents the ask order in the # step group. (See /:setup/:ask_step for details) # :after: <Data> Name of the previous <Data> to ask before the # current one. # :depends_on: # => Identify :data type required to be set before # the current one. # :default_value: Default value at setup time. This is not # necessarily the Application default value # (See /:default) # :validate: Regular expression to validate end user input # during setup. # :value_mapping: list of values to map as defined by the # controller # :controller: mapping for get controller value from process # values # <value> : <map> value map equivalence. See data_value_mapping # function # :process: mapping for get process value from controller # values # <value> : <map> value map equivalence. See data_value_mapping # function # :default: Default value. Replace /:default/<data> # :list_values: Defines a list of valid values for the current # data. # :query_type :controller_call to execute a function defined # in the controller object. # :process_call to execute a function defined in # the process object. # :values to get list of values from :values. # :object Object to load before calling the function. # Only :query_type = :*_call # :query_call Symbol. function name to call. # Only :query_type = :*_call # function must return an Array. # :query_params Hash. Controler function parameters. # Only :query_type = :*_call # :validate :list_strict. valid only if value is one of # thoselisted. # :values: to retrieve from. # otherwise define simply a list of possible # values. # :ask_step: Step number. By default, setup will determine # the step, thanks to meta lorj object # dependencies tree. # This number start at 0. Each step can be defined # by /:setup/:ask_step/<steps> list. # :pre_step_function: Process called before asking the data. # if it returns true, user interaction is # cancelled. # :post_step_function:Process called after asking the data. # if it returns false, the user is requested to # re-enter a new value. # # :setup: This section describes group of fields to ask, # step by step. # :ask_step: Define an Array of setup steps to ask to the # end user. The step order is respected, and # start at 0 # - :desc: Define the step description. ERB template # enable. To get config data, type config[...] # :explanation: |- Define a multiline explanation. This is printed # out in brown color. # ERB template enable. To get config data, type # <%= config[...] %> # :add: Define a list of additionnal fields to ask. # - <Data> Data to ask. # # :default: List of <Data> application default values. # <Data> : Value to use at the config application level. @meta_data = {} # The Generic Process can pre-define some data and value # (function predefine_data) # The Generic Process (and external framework call) only knows about # Generic data. # information used: # @meta_predefined_values = {} # <Data>: Data name # :values: List of possible values # <Value>: Value Name attached to the data # options: Options # :desc: Description of that predefine value. @context = { :oCurrentObj => nil, # Defines the Current Object to manipulate :needs_optional => nil, # set optional to true for any next needs # declaration :ClassProcess => nil, # Current Process Class declaration :oCurrentData => nil, # Current data model declaration :oCurrentObj => nil, # Current object declaration :oCurrentKey => nil # Current attribute declaration } # Available functions for: # - BaseDefinition class declaration # - Controler (derived from BaseDefinition) class declaration @query_auto_map = false # Model options @options = {} end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
26 27 28 |
# File 'lib/core/core_model.rb', line 26 def config @config end |
#meta_data ⇒ Object
Returns the value of attribute meta_data.
25 26 27 |
# File 'lib/core/core_model.rb', line 25 def @meta_data end |
#meta_obj ⇒ Object
Returns the value of attribute meta_obj.
25 26 27 |
# File 'lib/core/core_model.rb', line 25 def @meta_obj end |
#meta_predefined_values ⇒ Object
Returns the value of attribute meta_predefined_values.
25 26 27 |
# File 'lib/core/core_model.rb', line 25 def @meta_predefined_values end |
#query_auto_map ⇒ Object
Returns the value of attribute query_auto_map.
26 27 28 |
# File 'lib/core/core_model.rb', line 26 def query_auto_map @query_auto_map end |
Instance Method Details
#[](option) ⇒ Object
210 211 212 213 |
# File 'lib/core/core_model.rb', line 210 def [](option) return nil if option.nil? @options[option] if @options.key?(option) end |
#[]=(option, value) ⇒ Object
215 216 217 218 |
# File 'lib/core/core_model.rb', line 215 def []=(option, value) return nil if option.nil? @options[option] = value end |
#attribute_context(options = nil) ⇒ Object
Current Attribute identifier
parameters: (Hash)
-
option
: optional. KeyPath or a string.-
if option is a KeyPath, save the keypath.
-
if option is a Symbol, consider it as function_name for error report.
-
return:
-
string : KeyPath attribute
229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/core/core_model.rb', line 229 def attribute_context( = nil) function_name = nil function_name = .to_s if .is_a?(Symbol) @context[:oCurrentKey] = if .is_a?(KeyPath) msg = '' msg += '-' + function_name unless function_name.nil? msg += ': No model object attribute context defined. '\ 'Missing attr_mapping or obj_needs?' PrcLib.dcl_fail('%s%s', self.class, msg) if @context[:oCurrentKey].nil? @context[:oCurrentKey] end |
#clear_heap ⇒ Object
322 323 324 |
# File 'lib/core/core_model.rb', line 322 def clear_heap @context[:heap] = nil end |
#data_context(data = nil) ⇒ Object
Internal Current Data identifier
parameters: (Hash)
-
:data
: optional. Data name to keep in context.
return:
-
string : Data name
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/core/core_model.rb', line 251 def data_context(data = nil) @context[:oCurrentData] = data unless data.nil? data = @context[:oCurrentData] PrcLib.dcl_fail('Config data context not set. at least, you '\ 'need to call define_data before.') if data.nil? data end |
#heap(value = nil) ⇒ Object
317 318 319 320 |
# File 'lib/core/core_model.rb', line 317 def heap(value = nil) @context[:heap] = caller[1..-1] if value.is_a?(TrueClass) @context[:heap] end |
#needs_optional(value = nil) ⇒ Object
277 278 279 280 |
# File 'lib/core/core_model.rb', line 277 def needs_optional(value = nil) @context[:needs_optional] = value unless value.nil? || !value.boolean? @context[:needs_optional] end |
#needs_setup(value = nil) ⇒ Object
282 283 284 285 |
# File 'lib/core/core_model.rb', line 282 def needs_setup(value = nil) @context[:needs_setup] = value unless value.nil? || !value.boolean? @context[:needs_setup] end |
#object_context(options = nil) ⇒ Object
Object Context identifier (get/set) parameters:
-
options: Hash.
-
:object
: optional. Object to keep in context. -
:function_name
: optional. Symbol. Call function name for errorreport
-
return:
-
string : Object name
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/core/core_model.rb', line 295 def object_context( = nil) if .is_a?(Hash) if .key?(:object) @context[:oCurrentObj] = [:object] needs_optional false needs_setup false end else = {} end msg = '' if .rh_exist?(:function_name) && [:function_name].is_a?(Symbol) msg += '-' + [:function_name].to_s end msg += ': No model object context defined. Missing define_obj?' PrcLib.dcl_fail('%s%s', self.class, msg) if @context[:oCurrentObj].nil? @context[:oCurrentObj] end |
#options(options = nil) ⇒ Object
Model options (get/set) Uses Hash merge to set model options.
205 206 207 208 |
# File 'lib/core/core_model.rb', line 205 def ( = nil) @options.merge!() unless .nil? @options end |
#process_context(process = nil) ⇒ Object
Internal Current Process identifier parameters: (Hash)
-
:process
: optional. Process name to keep in context.
return:
-
string : Process name
267 268 269 270 271 272 273 274 275 |
# File 'lib/core/core_model.rb', line 267 def process_context(process = nil) @context[:ClassProcess] = process unless process.nil? process = @context[:ClassProcess] _lorj_dcl_error('Config process context not set. at least, you '\ 'need to call define_data before.') if process.nil? process end |