Class: RestfulObjects::ActionDescription
- Inherits:
-
Object
- Object
- RestfulObjects::ActionDescription
- Includes:
- LinkGenerator
- Defined in:
- lib/restful_objects/domain_model/types/action_description.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#disabled_reason ⇒ Object
Returns the value of attribute disabled_reason.
-
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind_result_type ⇒ Object
readonly
Returns the value of attribute kind_result_type.
-
#member_order ⇒ Object
Returns the value of attribute member_order.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#result_type ⇒ Object
readonly
Returns the value of attribute result_type.
Instance Method Summary collapse
- #get_representation ⇒ Object
- #has_params ⇒ Object
-
#initialize(id, domain_type, options) ⇒ ActionDescription
constructor
A new instance of ActionDescription.
- #metadata ⇒ Object
- #parameters_list ⇒ Object
Methods included from LinkGenerator
#generate_rel, #generate_repr_type, #link_to, #underscore_to_hyphen_string
Constructor Details
#initialize(id, domain_type, options) ⇒ ActionDescription
Returns a new instance of ActionDescription.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 10 def initialize(id, domain_type, ) @id = id @domain_type = domain_type @friendly_name = [:friendly_name] || id @description = [:description] || id @member_order = [:member_order] || 0 @disabled_reason = [:disabled_reason] || '' case [:return_type] when NilClass @result_type = :void @kind_result_type = :void when Symbol if [:return_type] == :void @result_type = :void @kind_result_type = :void else raise "result type for scalar '#{options[:return_type]}' unssuported" unless [:string, :int, :bool, :decimal, :date, :blob].include?([:return_type]) @result_type = [:return_type] @kind_result_type = :scalar end when Hash [:return_type] if [:return_type][:object] @result_type = [:return_type][:object] @kind_result_type = :object elsif [:return_type][:proto_object] @result_type = [:return_type][:proto_object] @kind_result_type = :proto_object elsif [:return_type][:list] @result_type = [:return_type][:list] @kind_result_type = :list else raise 'invalid return_type: object, proto_object or list key expected' end unless @result_type.is_a?(Class) or @result_type.is_a?(String) raise 'return_type object, proto_object or list value should be a class or a string' end else raise 'invalid return_type: symbol or hash expected' end @parameters = ParameterDescriptionList.new [:parameters].each { |name, definition| @parameters.add(name, definition) } if [:parameters] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 8 def description @description end |
#disabled_reason ⇒ Object
Returns the value of attribute disabled_reason.
8 9 10 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 8 def disabled_reason @disabled_reason end |
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
8 9 10 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 8 def friendly_name @friendly_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 7 def id @id end |
#kind_result_type ⇒ Object (readonly)
Returns the value of attribute kind_result_type.
7 8 9 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 7 def kind_result_type @kind_result_type end |
#member_order ⇒ Object
Returns the value of attribute member_order.
8 9 10 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 8 def member_order @member_order end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 7 def parameters @parameters end |
#result_type ⇒ Object (readonly)
Returns the value of attribute result_type.
7 8 9 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 7 def result_type @result_type end |
Instance Method Details
#get_representation ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 56 def get_representation representation = { 'id' => @id, 'hasParams' => has_params, 'memberOrder' => @member_order, 'parameters' => parameters_list, 'links' => [ link_to(:self, "/domain-types/#{@domain_type}/actions/#{@id}", :action_description), link_to(:up, "/domain-types/#{@domain_type}", :domain_type), link_to(:return_type, "/domain-types/#{result_type}", :domain_type) ], 'extensions' => {} } representation['friendlyName'] = friendly_name if friendly_name representation['description'] = description if description representation.to_json end |
#has_params ⇒ Object
86 87 88 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 86 def has_params not @parameters.empty? end |
#metadata ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 76 def { 'friendlyName' => friendly_name, 'description' => description, 'returnType' => result_type, 'hasParams' => has_params, 'memberOrder' => member_order } end |
#parameters_list ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/restful_objects/domain_model/types/action_description.rb', line 90 def parameters_list result = {} parameters.each do |name, parameter| result[name] = { 'extension' => parameter. } end result end |