Class: RestfulObjects::ActionDescription
- Inherits:
-
Object
- Object
- RestfulObjects::ActionDescription
- Includes:
- LinkGenerator
- Defined in:
- lib/restful_objects/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, result_type, domain_type, parameters = {}, 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, result_type, domain_type, parameters = {}, options = {}) ⇒ ActionDescription
8 9 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 |
# File 'lib/restful_objects/action_description.rb', line 8 def initialize(id, result_type, domain_type, parameters = {}, = {}) @id = id if result_type == :void result_type = [:void, :void] elsif result_type.is_a?(Symbol) result_type = [:scalar, result_type] end raise "result type should be a symbol or an array" if not result_type.is_a?(Array) raise "result type kind '#{result_type.last}' unssuported" if not [:void, :scalar, :object, :proto_object, :list].include?(result_type.first) @kind_result_type = result_type.first @result_type = result_type.last case @kind_result_type when :scalar raise "result type for scalar '#{result_type.last}' unssuported" if not [:string, :int, :decimal, :date, :blob].include?(@result_type) when :object, :proto_object, :list raise "result type should be a class or a string with a class name" if not (@result_type.is_a?(Class) || @result_type.is_a?(String)) end @parameters = ParameterDescriptionList.new parameters.each { |name, definition| @parameters.add(name, definition) } @domain_type = domain_type @friendly_name = [:friendly_name] || id @description = [:description] || id @member_order = [:member_order] || 0 @disabled_reason = [:disabled_reason] || '' end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/restful_objects/action_description.rb', line 6 def description @description end |
#disabled_reason ⇒ Object
Returns the value of attribute disabled_reason.
6 7 8 |
# File 'lib/restful_objects/action_description.rb', line 6 def disabled_reason @disabled_reason end |
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
6 7 8 |
# File 'lib/restful_objects/action_description.rb', line 6 def friendly_name @friendly_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/restful_objects/action_description.rb', line 5 def id @id end |
#kind_result_type ⇒ Object (readonly)
Returns the value of attribute kind_result_type.
5 6 7 |
# File 'lib/restful_objects/action_description.rb', line 5 def kind_result_type @kind_result_type end |
#member_order ⇒ Object
Returns the value of attribute member_order.
6 7 8 |
# File 'lib/restful_objects/action_description.rb', line 6 def member_order @member_order end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
5 6 7 |
# File 'lib/restful_objects/action_description.rb', line 5 def parameters @parameters end |
#result_type ⇒ Object (readonly)
Returns the value of attribute result_type.
5 6 7 |
# File 'lib/restful_objects/action_description.rb', line 5 def result_type @result_type end |
Instance Method Details
#get_representation ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/restful_objects/action_description.rb', line 40 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
68 69 70 |
# File 'lib/restful_objects/action_description.rb', line 68 def has_params not @parameters.empty? end |
#metadata ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/restful_objects/action_description.rb', line 60 def result = { 'friendlyName' => friendly_name, 'description' => description, 'returnType' => result_type, 'hasParams' => has_params, 'memberOrder' => member_order } end |
#parameters_list ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/restful_objects/action_description.rb', line 72 def parameters_list result = {} parameters.each do |name, parameter| result[name] = { 'extension' => parameter. } end result end |