restful_objects 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/restful_objects.rb +1 -2
- data/lib/restful_objects/domain_model/domain_model.rb +14 -11
- data/lib/restful_objects/domain_model/helpers/link_generator.rb +102 -90
- data/lib/restful_objects/domain_model/mixins/object.rb +10 -13
- data/lib/restful_objects/domain_model/mixins/object_actions.rb +106 -117
- data/lib/restful_objects/domain_model/mixins/object_base.rb +175 -131
- data/lib/restful_objects/domain_model/mixins/object_collections.rb +58 -71
- data/lib/restful_objects/domain_model/mixins/object_macros.rb +20 -26
- data/lib/restful_objects/domain_model/mixins/object_properties.rb +85 -98
- data/lib/restful_objects/domain_model/mixins/service.rb +9 -17
- data/lib/restful_objects/domain_model/types/action_description.rb +80 -82
- data/lib/restful_objects/domain_model/types/collection_description.rb +39 -40
- data/lib/restful_objects/domain_model/types/domain_type.rb +102 -105
- data/lib/restful_objects/domain_model/types/parameter_description.rb +42 -47
- data/lib/restful_objects/domain_model/types/parameter_description_list.rb +9 -12
- data/lib/restful_objects/domain_model/types/property_description.rb +62 -64
- data/lib/restful_objects/router.rb +6 -0
- data/lib/restful_objects/router/base.rb +23 -32
- data/lib/restful_objects/router/domain_object_resources.rb +89 -94
- data/lib/restful_objects/router/domain_type_resources.rb +24 -29
- data/lib/restful_objects/router/supporting_resources.rb +26 -31
- data/lib/restful_objects/version.rb +1 -1
- data/spec/integration/domain-types_actions_spec.rb +1 -3
- data/spec/integration/domain-types_collections_spec.rb +1 -39
- data/spec/integration/domain-types_properties_spec.rb +1 -78
- data/spec/integration/domain-types_spec.rb +39 -0
- data/spec/integration/{server-root_spec.rb → homepage_spec.rb} +2 -3
- data/spec/integration/objects_actions_spec.rb +7 -0
- data/spec/integration/objects_collections_spec.rb +169 -0
- data/spec/integration/objects_properties_spec.rb +122 -0
- data/spec/{acceptance/generate_json_representations_spec.rb → integration/objects_spec.rb} +12 -4
- data/spec/unit/object_actions_spec.rb +5 -5
- data/spec/unit/object_collections_spec.rb +1 -1
- data/spec/unit/object_properties_spec.rb +6 -6
- data/spec/unit/object_spec.rb +9 -9
- data/spec/unit/service_spec.rb +5 -5
- metadata +54 -35
- data/spec/integration/domain_model_spec.rb +0 -35
- data/spec/unit/type_list_spec.rb +0 -37
| @@ -1,47 +1,46 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
               | 
| 3 | 
            -
                include LinkGenerator
         | 
| 4 | 
            -
                attr_reader :id, :type, :read_only
         | 
| 5 | 
            -
                attr_accessor :friendly_name, :description, :plural_form, :member_order, :disabled_reason
         | 
| 1 | 
            +
            class RestfulObjects::CollectionDescription
         | 
| 2 | 
            +
              include RestfulObjects::LinkGenerator
         | 
| 6 3 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
                  @type = type
         | 
| 10 | 
            -
                  @domain_type = domain_type
         | 
| 11 | 
            -
                  @read_only = options[:read_only].nil? ? false : options[:read_only]
         | 
| 12 | 
            -
                  @disabled_reason = options[:disabled_reason] || 'read only collection' if read_only
         | 
| 13 | 
            -
                  @friendly_name = options[:friendly_name] || id
         | 
| 14 | 
            -
                  @description = options[:description] || id
         | 
| 15 | 
            -
                  @plural_form = options[:plural_form]
         | 
| 16 | 
            -
                  @member_order = options[:member_order]
         | 
| 17 | 
            -
                end
         | 
| 4 | 
            +
              attr_reader :id, :type, :read_only
         | 
| 5 | 
            +
              attr_accessor :friendly_name, :description, :plural_form, :member_order, :disabled_reason
         | 
| 18 6 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 7 | 
            +
              def initialize(id, type, domain_type, options = {})
         | 
| 8 | 
            +
                @id = id
         | 
| 9 | 
            +
                @type = type
         | 
| 10 | 
            +
                @domain_type = domain_type
         | 
| 11 | 
            +
                @read_only = options[:read_only].nil? ? false : options[:read_only]
         | 
| 12 | 
            +
                @disabled_reason = options[:disabled_reason] || 'read only collection' if read_only
         | 
| 13 | 
            +
                @friendly_name = options[:friendly_name] || id
         | 
| 14 | 
            +
                @description = options[:description] || id
         | 
| 15 | 
            +
                @plural_form = options[:plural_form]
         | 
| 16 | 
            +
                @member_order = options[:member_order]
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def get_representation
         | 
| 20 | 
            +
                representation = {
         | 
| 21 | 
            +
                  'id' => id,
         | 
| 22 | 
            +
                  'memberOrder' => member_order,
         | 
| 23 | 
            +
                  'links' => [
         | 
| 24 | 
            +
                    link_to(:self, "/domain-types/#{@domain_type}/collections/#{@id}", :collection_description),
         | 
| 25 | 
            +
                    link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
         | 
| 26 | 
            +
                    link_to(:return_type, "/domain-types/list", :domain_type),
         | 
| 27 | 
            +
                    link_to(:element_type, "/domain-types/#{@type}", :domain_type)
         | 
| 28 | 
            +
                  ],
         | 
| 29 | 
            +
                  'extensions' => metadata
         | 
| 30 | 
            +
                }
         | 
| 31 31 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 32 | 
            +
                representation['friendlyName'] = friendly_name if friendly_name
         | 
| 33 | 
            +
                representation['description'] = description if description
         | 
| 34 34 |  | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 35 | 
            +
                representation.to_json
         | 
| 36 | 
            +
              end
         | 
| 37 37 |  | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
                end
         | 
| 38 | 
            +
              def metadata
         | 
| 39 | 
            +
                { 'friendlyName' => friendly_name,
         | 
| 40 | 
            +
                  'description' => description,
         | 
| 41 | 
            +
                  'returnType' => 'list',
         | 
| 42 | 
            +
                  'elementType' => type,
         | 
| 43 | 
            +
                  'memberOrder' => member_order,
         | 
| 44 | 
            +
                  'pluralForm' => plural_form }
         | 
| 46 45 | 
             
              end
         | 
| 47 46 | 
             
            end
         | 
| @@ -2,129 +2,126 @@ require_relative 'property_description' | |
| 2 2 | 
             
            require_relative 'collection_description'
         | 
| 3 3 | 
             
            require_relative 'action_description'
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
               | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
                 | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
                end
         | 
| 5 | 
            +
            class RestfulObjects::DomainType
         | 
| 6 | 
            +
              include RestfulObjects::LinkGenerator
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              attr_reader :id, :is_service, :properties, :collections, :actions
         | 
| 9 | 
            +
              attr_accessor :friendly_name, :plural_name, :description
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def initialize(id)
         | 
| 12 | 
            +
                @id            = id
         | 
| 13 | 
            +
                @properties    = {}
         | 
| 14 | 
            +
                @collections   = {}
         | 
| 15 | 
            +
                @actions       = {}
         | 
| 16 | 
            +
                @is_service    = false
         | 
| 17 | 
            +
                @friendly_name = ''
         | 
| 18 | 
            +
                @plural_name   = ''
         | 
| 19 | 
            +
                @description   = ''
         | 
| 20 | 
            +
              end
         | 
| 22 21 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 22 | 
            +
              def register_property(name, return_type, options = {})
         | 
| 23 | 
            +
                options[:member_order] ||= @properties.count + 1
         | 
| 24 | 
            +
                @properties[name]        = RestfulObjects::PropertyDescription.new(name, @id, return_type, options)
         | 
| 25 | 
            +
              end
         | 
| 27 26 |  | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 27 | 
            +
              def register_collection(name, type, options = {})
         | 
| 28 | 
            +
                options[:member_order] ||= @collections.count + 1
         | 
| 29 | 
            +
                @collections[name]       = RestfulObjects::CollectionDescription.new(name, type, @id, options)
         | 
| 30 | 
            +
              end
         | 
| 32 31 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 32 | 
            +
              def register_action(name, options = {})
         | 
| 33 | 
            +
                options[:member_order] ||= @actions.count + 1
         | 
| 34 | 
            +
                @actions[name]           = RestfulObjects::ActionDescription.new(name, @id, options)
         | 
| 35 | 
            +
              end
         | 
| 37 36 |  | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 37 | 
            +
              def get_representation
         | 
| 38 | 
            +
                { 'name' => @id,
         | 
| 39 | 
            +
                  'domainType' => @id,
         | 
| 40 | 
            +
                  'friendlyName' => @friendly_name,
         | 
| 41 | 
            +
                  'pluralName' => @plural_name,
         | 
| 42 | 
            +
                  'description' => @description,
         | 
| 43 | 
            +
                  'isService' => @is_service,
         | 
| 44 | 
            +
                  'members' => get_members,
         | 
| 45 | 
            +
                  'typeActions' => get_type_actions,
         | 
| 46 | 
            +
                  'links' => [ link_to(:self, "/domain-types/#{@id}", :domain_type) ],
         | 
| 47 | 
            +
                  'extensions' => {}
         | 
| 48 | 
            +
                }.to_json
         | 
| 49 | 
            +
              end
         | 
| 51 50 |  | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
                    end
         | 
| 62 | 
            -
                    members[name] = { 'value' => nil }
         | 
| 51 | 
            +
              def new_proto_persistent_object
         | 
| 52 | 
            +
                persist_link = link_to(:persist, "/objects/#{id}", :object, method: 'POST')
         | 
| 53 | 
            +
                persist_link['arguments'] = { 'members' => {} }
         | 
| 54 | 
            +
                members = {}
         | 
| 55 | 
            +
                properties.each do |name, property|
         | 
| 56 | 
            +
                  if not property.optional
         | 
| 57 | 
            +
                    persist_link['arguments']['members'][name] = {
         | 
| 58 | 
            +
                      'value' => nil,
         | 
| 59 | 
            +
                      'extensions' => property.metadata }
         | 
| 63 60 | 
             
                  end
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                  { 'title' => "New #{id}",
         | 
| 66 | 
            -
                    'members' => members,
         | 
| 67 | 
            -
                    'links' => [ persist_link ],
         | 
| 68 | 
            -
                    'extensions' => {} }
         | 
| 61 | 
            +
                  members[name] = { 'value' => nil }
         | 
| 69 62 | 
             
                end
         | 
| 70 63 |  | 
| 71 | 
            -
                 | 
| 72 | 
            -
                  members  | 
| 64 | 
            +
                { 'title' => "New #{id}",
         | 
| 65 | 
            +
                  'members' => members,
         | 
| 66 | 
            +
                  'links' => [ persist_link ],
         | 
| 67 | 
            +
                  'extensions' => {} }
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              def post_prototype_object(members_json)
         | 
| 71 | 
            +
                members = JSON.parse(members_json)['members']
         | 
| 73 72 |  | 
| 74 | 
            -
             | 
| 73 | 
            +
                new_object = Object.const_get(@id.to_sym).new
         | 
| 75 74 |  | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
                    end
         | 
| 75 | 
            +
                members.each do |name, value|
         | 
| 76 | 
            +
                  if properties.include?(name) then
         | 
| 77 | 
            +
                    new_object.ro_put_property_and_get_response(name, value.to_json)
         | 
| 78 | 
            +
                  else
         | 
| 79 | 
            +
                    raise "member of property '#{name}' not found in type '#{@id}'"
         | 
| 82 80 | 
             
                  end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                  new_object.get_representation
         | 
| 85 81 | 
             
                end
         | 
| 86 82 |  | 
| 87 | 
            -
                 | 
| 88 | 
            -
             | 
| 89 | 
            -
                    'friendlyName' => friendly_name,
         | 
| 90 | 
            -
                    'pluralName' => plural_name,
         | 
| 91 | 
            -
                    'description' => description,
         | 
| 92 | 
            -
                    'isService' => is_service }
         | 
| 93 | 
            -
                end
         | 
| 83 | 
            +
                new_object.ro_get_representation_response
         | 
| 84 | 
            +
              end
         | 
| 94 85 |  | 
| 95 | 
            -
             | 
| 86 | 
            +
              def metadata
         | 
| 87 | 
            +
                { 'domainType' => id,
         | 
| 88 | 
            +
                  'friendlyName' => friendly_name,
         | 
| 89 | 
            +
                  'pluralName' => plural_name,
         | 
| 90 | 
            +
                  'description' => description,
         | 
| 91 | 
            +
                  'isService' => is_service }
         | 
| 92 | 
            +
              end
         | 
| 96 93 |  | 
| 97 | 
            -
             | 
| 98 | 
            -
                    properties_members.merge(collections_members.merge(actions_members))
         | 
| 99 | 
            -
                  end
         | 
| 94 | 
            +
              protected
         | 
| 100 95 |  | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
                      result[name] = link_to(:property, "/domain-types/#{@id}/properties/#{name}", :property_description)
         | 
| 105 | 
            -
                    end
         | 
| 106 | 
            -
                    result
         | 
| 107 | 
            -
                  end
         | 
| 96 | 
            +
              def get_members
         | 
| 97 | 
            +
                ro_properties_members.merge(collections_members.merge(actions_members))
         | 
| 98 | 
            +
              end
         | 
| 108 99 |  | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 100 | 
            +
              def properties_members
         | 
| 101 | 
            +
                result = {}
         | 
| 102 | 
            +
                @properties.each do |name, property|
         | 
| 103 | 
            +
                  result[name] = link_to(:property, "/domain-types/#{@id}/properties/#{name}", :property_description)
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
                result
         | 
| 106 | 
            +
              end
         | 
| 116 107 |  | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 108 | 
            +
              def collections_members
         | 
| 109 | 
            +
                result = {}
         | 
| 110 | 
            +
                @collections.each do |name, collection|
         | 
| 111 | 
            +
                  result[name] = link_to(:collection, "/domain-types/#{@id}/collections/#{name}", :collection_description)
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
                result
         | 
| 114 | 
            +
              end
         | 
| 124 115 |  | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 116 | 
            +
              def actions_members
         | 
| 117 | 
            +
                result = {}
         | 
| 118 | 
            +
                @actions.each do |name, action|
         | 
| 119 | 
            +
                  result[name] = link_to(:action, "/domain-types/#{@id}/actions/#{name}", :action_description)
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
                result
         | 
| 128 122 | 
             
              end
         | 
| 129 | 
            -
            end
         | 
| 130 123 |  | 
| 124 | 
            +
              def get_type_actions
         | 
| 125 | 
            +
                {}
         | 
| 126 | 
            +
              end
         | 
| 127 | 
            +
            end
         | 
| @@ -1,60 +1,55 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
               | 
| 3 | 
            -
                include LinkGenerator
         | 
| 1 | 
            +
            class RestfulObjects::ParameterDescription
         | 
| 2 | 
            +
              include RestfulObjects::LinkGenerator
         | 
| 4 3 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 4 | 
            +
              attr_reader :id, :name, :number, :kind_type, :type
         | 
| 5 | 
            +
              attr_accessor :friendly_name, :description, :optional, :max_length, :pattern, :format
         | 
| 7 6 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 7 | 
            +
              def initialize(id, definition, number)
         | 
| 8 | 
            +
                @id = id
         | 
| 9 | 
            +
                @name = id
         | 
| 11 10 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
                      @kind_type = :scalar
         | 
| 15 | 
            -
                      @type = definition.first
         | 
| 16 | 
            -
                    elsif definition.first.is_a?(Class) # object type
         | 
| 17 | 
            -
                      @kind_type = :object
         | 
| 18 | 
            -
                      @type = definition.first.name
         | 
| 19 | 
            -
                    elsif definition.first.is_a?(Strign) # object type
         | 
| 20 | 
            -
                      @kind_type = :object
         | 
| 21 | 
            -
                      @type = definition.first
         | 
| 22 | 
            -
                    else
         | 
| 23 | 
            -
                      raise "unssuported parameter definition type #{definition.class}"
         | 
| 24 | 
            -
                    end
         | 
| 25 | 
            -
                    options = definition.last
         | 
| 26 | 
            -
                  elsif definition.is_a? Symbol # scalar type
         | 
| 11 | 
            +
                if definition.is_a?(Array)# [type, options]
         | 
| 12 | 
            +
                  if [:string, :int, :decimal, :date, :blob].include?(definition.first) # scalar
         | 
| 27 13 | 
             
                    @kind_type = :scalar
         | 
| 28 | 
            -
                    @type = definition
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  elsif definition.is_a? String # object type
         | 
| 14 | 
            +
                    @type = definition.first
         | 
| 15 | 
            +
                  elsif definition.first.is_a?(Class) # object type
         | 
| 31 16 | 
             
                    @kind_type = :object
         | 
| 32 | 
            -
                    @type = definition
         | 
| 33 | 
            -
                  elsif definition.is_a?  | 
| 17 | 
            +
                    @type = definition.first.name
         | 
| 18 | 
            +
                  elsif definition.first.is_a?(Strign) # object type
         | 
| 34 19 | 
             
                    @kind_type = :object
         | 
| 35 | 
            -
                    @type = definition. | 
| 20 | 
            +
                    @type = definition.first
         | 
| 36 21 | 
             
                  else
         | 
| 37 22 | 
             
                    raise "unssuported parameter definition type #{definition.class}"
         | 
| 38 23 | 
             
                  end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
                  @ | 
| 42 | 
            -
                  @ | 
| 43 | 
            -
                  @ | 
| 44 | 
            -
             | 
| 45 | 
            -
                  @ | 
| 46 | 
            -
                  @ | 
| 24 | 
            +
                  options = definition.last
         | 
| 25 | 
            +
                elsif definition.is_a?(Symbol) # scalar type
         | 
| 26 | 
            +
                  @kind_type = :scalar
         | 
| 27 | 
            +
                  @type = definition
         | 
| 28 | 
            +
                  raise "result type for scalar '#{@type}' unssuported" unless [:string, :int, :decimal, :date, :blob].include?(@type)
         | 
| 29 | 
            +
                elsif definition.is_a?(String)# object type
         | 
| 30 | 
            +
                  @kind_type = :object
         | 
| 31 | 
            +
                  @type = definition
         | 
| 32 | 
            +
                elsif definition.is_a?(Class)# object type
         | 
| 33 | 
            +
                  @kind_type = :object
         | 
| 34 | 
            +
                  @type = definition.to_s
         | 
| 35 | 
            +
                else
         | 
| 36 | 
            +
                  raise "unssuported parameter definition type #{definition.class}"
         | 
| 47 37 | 
             
                end
         | 
| 48 38 |  | 
| 49 | 
            -
                 | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 39 | 
            +
                options ||= {}
         | 
| 40 | 
            +
                @number = options[:number] || number
         | 
| 41 | 
            +
                @friendly_name = options[:friendly_name] || id
         | 
| 42 | 
            +
                @description = options[:description] || id
         | 
| 43 | 
            +
                @optional = options[:optional].nil? ? true : options[:optional]
         | 
| 44 | 
            +
                @max_length = options[:max_length]
         | 
| 45 | 
            +
                @pattern = options[:pattern]
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              def metadata
         | 
| 49 | 
            +
                result = { 'friendlyName' => friendly_name, 'description' => description, 'optional' => optional, 'returnType' => type }
         | 
| 50 | 
            +
                result['maxLength'] = max_length if max_length
         | 
| 51 | 
            +
                result['pattern'] = pattern if pattern
         | 
| 52 | 
            +
                result['format'] = format if format
         | 
| 53 | 
            +
                result
         | 
| 59 54 | 
             
              end
         | 
| 60 55 | 
             
            end
         | 
| @@ -1,18 +1,15 @@ | |
| 1 1 | 
             
            require_relative 'parameter_description'
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
               | 
| 5 | 
            -
                extend Forwardable
         | 
| 3 | 
            +
            class RestfulObjects::ParameterDescriptionList
         | 
| 4 | 
            +
              extend Forwardable
         | 
| 6 5 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
                def add(id, definition)
         | 
| 12 | 
            -
                  @parameters[id] = ParameterDescription.new(id, definition, count + 1)
         | 
| 13 | 
            -
                end
         | 
| 6 | 
            +
              def initialize
         | 
| 7 | 
            +
                @parameters = Hash.new
         | 
| 8 | 
            +
              end
         | 
| 14 9 |  | 
| 15 | 
            -
             | 
| 10 | 
            +
              def add(id, definition)
         | 
| 11 | 
            +
                @parameters[id] = RestfulObjects::ParameterDescription.new(id, definition, count + 1)
         | 
| 16 12 | 
             
              end
         | 
| 17 | 
            -
            end
         | 
| 18 13 |  | 
| 14 | 
            +
              def_delegators :@parameters, :[], :each, :include?, :count, :empty?
         | 
| 15 | 
            +
            end
         | 
| @@ -1,75 +1,73 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
               | 
| 3 | 
            -
                include LinkGenerator
         | 
| 1 | 
            +
            class RestfulObjects::PropertyDescription
         | 
| 2 | 
            +
              include RestfulObjects::LinkGenerator
         | 
| 4 3 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 4 | 
            +
              attr_accessor :id, :domain_type, :return_type, :is_reference, :friendly_name, :description, :optional, :read_only,
         | 
| 5 | 
            +
                            :member_order, :max_length, :disabled_reason, :pattern
         | 
| 7 6 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
                  end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                  @id              = id
         | 
| 16 | 
            -
                  @domain_type     = domain_type
         | 
| 17 | 
            -
                  if return_type.is_a?(Hash)
         | 
| 18 | 
            -
                    @return_type  = return_type[:object]
         | 
| 19 | 
            -
                    @is_reference = true
         | 
| 20 | 
            -
                  else
         | 
| 21 | 
            -
                    @return_type  = return_type
         | 
| 22 | 
            -
                    @is_reference = false
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                  @friendly_name   = options[:friendly_name] || id
         | 
| 25 | 
            -
                  @description     = options[:description] || id
         | 
| 26 | 
            -
                  @optional        = options[:optional].nil? ? true : options[:optional]
         | 
| 27 | 
            -
                  @read_only       = options[:read_only].nil? ? false : options[:read_only]
         | 
| 28 | 
            -
                  @member_order    = options[:member_order] || 1
         | 
| 29 | 
            -
                  @max_length      = options[:max_length]
         | 
| 30 | 
            -
                  @disabled_reason = options[:disabled_reason] || 'read-only property' if read_only
         | 
| 31 | 
            -
                  @pattern         = options[:pattern]
         | 
| 7 | 
            +
              def initialize(id, domain_type, return_type, options)
         | 
| 8 | 
            +
                if return_type.is_a?(Hash)
         | 
| 9 | 
            +
                  raise "hash with :object key expected for property reference" unless return_type.has_key?(:object)
         | 
| 10 | 
            +
                else
         | 
| 11 | 
            +
                  raise "property type #{return_type} usupported" unless [:string, :int, :bool, :decimal, :date, :blob].include?(return_type)
         | 
| 32 12 | 
             
                end
         | 
| 33 13 |  | 
| 34 | 
            -
                 | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
                      link_to(:self, "/domain-types/#{@domain_type}/properties/#{@id}", :property_description),
         | 
| 43 | 
            -
                      link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
         | 
| 44 | 
            -
                      link_to(:return_type, "/domain-types/#{@return_type}", :domain_type)
         | 
| 45 | 
            -
                    ],
         | 
| 46 | 
            -
                    'extensions' => {}
         | 
| 47 | 
            -
                  }.to_json
         | 
| 14 | 
            +
                @id              = id
         | 
| 15 | 
            +
                @domain_type     = domain_type
         | 
| 16 | 
            +
                if return_type.is_a?(Hash)
         | 
| 17 | 
            +
                  @return_type  = return_type[:object]
         | 
| 18 | 
            +
                  @is_reference = true
         | 
| 19 | 
            +
                else
         | 
| 20 | 
            +
                  @return_type  = return_type
         | 
| 21 | 
            +
                  @is_reference = false
         | 
| 48 22 | 
             
                end
         | 
| 23 | 
            +
                @friendly_name   = options[:friendly_name] || id
         | 
| 24 | 
            +
                @description     = options[:description] || id
         | 
| 25 | 
            +
                @optional        = options[:optional].nil? ? true : options[:optional]
         | 
| 26 | 
            +
                @read_only       = options[:read_only].nil? ? false : options[:read_only]
         | 
| 27 | 
            +
                @member_order    = options[:member_order] || 1
         | 
| 28 | 
            +
                @max_length      = options[:max_length]
         | 
| 29 | 
            +
                @disabled_reason = options[:disabled_reason] || 'read-only property' if read_only
         | 
| 30 | 
            +
                @pattern         = options[:pattern]
         | 
| 31 | 
            +
              end
         | 
| 49 32 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
                   | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 33 | 
            +
              def get_representation
         | 
| 34 | 
            +
                {
         | 
| 35 | 
            +
                  'id'           => @id,
         | 
| 36 | 
            +
                  'friendlyName' => friendly_name || '',
         | 
| 37 | 
            +
                  'description'  => description || '',
         | 
| 38 | 
            +
                  'optional'     => optional,
         | 
| 39 | 
            +
                  'memberOrder'  => @member_order,
         | 
| 40 | 
            +
                  'links'        => [
         | 
| 41 | 
            +
                    link_to(:self, "/domain-types/#{@domain_type}/properties/#{@id}", :property_description),
         | 
| 42 | 
            +
                    link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
         | 
| 43 | 
            +
                    link_to(:return_type, "/domain-types/#{@return_type}", :domain_type)
         | 
| 44 | 
            +
                  ],
         | 
| 45 | 
            +
                  'extensions' => {}
         | 
| 46 | 
            +
                }.to_json
         | 
| 47 | 
            +
              end
         | 
| 61 48 |  | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 49 | 
            +
              def metadata
         | 
| 50 | 
            +
                result = { 'friendlyName' => friendly_name,
         | 
| 51 | 
            +
                           'description' => description,
         | 
| 52 | 
            +
                           'returnType' => return_type,
         | 
| 53 | 
            +
                           'format' => format,
         | 
| 54 | 
            +
                           'optional' => optional,
         | 
| 55 | 
            +
                           'memberOrder' => member_order }
         | 
| 56 | 
            +
                result['maxLength'] = max_length if max_length
         | 
| 57 | 
            +
                result['pattern'] = pattern if pattern
         | 
| 58 | 
            +
                result
         | 
| 59 | 
            +
              end
         | 
| 68 60 |  | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 61 | 
            +
              def format
         | 
| 62 | 
            +
                case return_type
         | 
| 63 | 
            +
                  when :string
         | 
| 64 | 
            +
                    'string'
         | 
| 73 65 | 
             
                end
         | 
| 74 66 | 
             
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              def get_value_as_json
         | 
| 69 | 
            +
                { 'id' =>
         | 
| 70 | 
            +
                  { 'value' => '' }
         | 
| 71 | 
            +
                }.to_json
         | 
| 72 | 
            +
              end
         | 
| 75 73 | 
             
            end
         |