class Safrano::FunctionImport::Function
Attributes
name[R]
proc[R]
Public Class Methods
new(name)
click to toggle source
# File lib/odata/function_import.rb, line 18 def initialize(name) @name = name @http_method = 'GET' end
Public Instance Methods
add_metadata_rexml(ec)
click to toggle source
# File lib/odata/function_import.rb, line 127 def add_metadata_rexml(ec) ## https://services.odata.org/V2/OData/Safrano.svc/$metadata # <FunctionImport Name="GetProductsByRating" EntitySet="Products" ReturnType="Collection(ODataDemo.Product)" m:HttpMethod="GET"> # <Parameter Name="rating" Type="Edm.Int32" Mode="In"/> # </FunctionImport> funky = ec.add_element('FunctionImport', 'Name' => @name.to_s, # EntitySet= @entity_set , 'ReturnType' => @returning.type_metadata, 'm:HttpMethod' => @http_method) @input.each do |iname, type| funky.add_element('Parameter', 'Name' => iname.to_s, 'Type' => type.type_name, 'Mode' => 'In') end if @input funky end
allowed_transitions()
click to toggle source
# File lib/odata/function_import.rb, line 23 def allowed_transitions [Safrano::TransitionExecuteFunc] end
auto_query_parameters()
click to toggle source
# File lib/odata/function_import.rb, line 46 def auto_query_parameters @auto_query_params = true self # chaining end
Also aliased as: auto_query_params
check_missing_params()
click to toggle source
def initialize_params
@uparms = UrlParameters4Func.new(@model, @params)
end
# File lib/odata/function_import.rb, line 84 def check_missing_params # do we have all parameters provided ? use Set difference to check pkeys = @params.keys.map(&:to_sym).to_set unless (idiff = @input.keys.to_set - pkeys).empty? Safrano::ServiceOperationParameterMissing.new( missing: idiff.to_a, sopname: @name ) else Contract::OK end end
check_url_func_params()
click to toggle source
# File lib/odata/function_import.rb, line 98 def check_url_func_params @funcparams = {} return nil unless @input # anything to check ? # do we have all parameters provided ? check_missing_params.tap_error { |error| return error } # ==> all params were provided # now we shall check the content and type of the parameters @input.each do |ksym, typ| typ.convert_from_urlparam(v = @params[ksym.to_s]) .tap_valid do |retval| @funcparams[ksym] = retval end .tap_error do # return is really needed here, or we end up returning nil below return parameter_convertion_error(ksym, typ, v) end end nil end
do_execute_func(req)
click to toggle source
# File lib/odata/function_import.rb, line 154 def do_execute_func(req) with_transition_validated(req) do result = @proc.call(**@funcparams) [@returning.do_execute_func_result(result, req, @auto_query_params), :run] end end
input(**parmtypes)
click to toggle source
# File lib/odata/function_import.rb, line 27 def input(**parmtypes) @input = {} parmtypes.each do |k, t| @input[k] = case t.name when 'Integer' Safrano::Edm::Edm::Int32 when 'String' Safrano::Edm::Edm::String when 'Float' Safrano::Edm::Edm::Double when 'DateTime' Safrano::Edm::Edm::DateTime else t end end self end
parameter_convertion_error(param, type, val)
click to toggle source
# File lib/odata/function_import.rb, line 120 def parameter_convertion_error(param, type, val) Safrano::ServiceOperationParameterError.new(type: type, value: val, param: param, sopname: @name) end
return(klassmod, &proc)
click to toggle source
# File lib/odata/function_import.rb, line 52 def return(klassmod, &proc) raise('Please provide a code block') unless block_given? @returning = if klassmod.respond_to? :return_as_instance_descriptor klassmod.return_as_instance_descriptor else # if it's neither a ComplexType nor a Model-Entity # --> assume it is a Primitive ResultDefinition.asPrimitiveType(klassmod) end @proc = proc self end
return_collection(klassmod, &proc)
click to toggle source
# File lib/odata/function_import.rb, line 66 def return_collection(klassmod, &proc) raise('Please provide a code block') unless block_given? @returning = if klassmod.respond_to? :return_as_collection_descriptor klassmod.return_as_collection_descriptor else # if it's neither a ComplexType nor a Modle-Entity # --> assume it is a Primitive # ResultAsPrimitiveTypeColl.new(klassmod) ResultDefinition.asPrimitiveTypeColl(klassmod) end @proc = proc self end
transition_execute_func(_match_result)
click to toggle source
# File lib/odata/function_import.rb, line 161 def transition_execute_func(_match_result) [self, :run_with_execute_func] end
with_transition_validated(req) { || ... }
click to toggle source
# File lib/odata/function_import.rb, line 146 def with_transition_validated(req) # initialize_params @params = req.params return yield unless (@error = check_url_func_params) [nil, :error, @error] if @error end