restful_objects 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +3 -2
  3. data/bin/restful_server.rb +0 -0
  4. data/lib/restful_objects/action_description.rb +96 -82
  5. data/lib/restful_objects/action_list.rb +17 -17
  6. data/lib/restful_objects/collection_description.rb +47 -47
  7. data/lib/restful_objects/collection_list.rb +17 -17
  8. data/lib/restful_objects/domain_model.rb +83 -79
  9. data/lib/restful_objects/http_response.rb +11 -11
  10. data/lib/restful_objects/link_generator.rb +104 -104
  11. data/lib/restful_objects/object.rb +20 -20
  12. data/lib/restful_objects/object_actions.rb +134 -134
  13. data/lib/restful_objects/object_base.rb +10 -0
  14. data/lib/restful_objects/object_collections.rb +84 -84
  15. data/lib/restful_objects/object_list.rb +16 -16
  16. data/lib/restful_objects/object_macros.rb +35 -35
  17. data/lib/restful_objects/object_properties.rb +78 -78
  18. data/lib/restful_objects/parameter_description.rb +60 -60
  19. data/lib/restful_objects/parameter_description_list.rb +15 -15
  20. data/lib/restful_objects/property_description.rb +68 -68
  21. data/lib/restful_objects/property_list.rb +17 -17
  22. data/lib/restful_objects/service.rb +21 -21
  23. data/lib/restful_objects/service_list.rb +55 -55
  24. data/lib/restful_objects/type.rb +110 -110
  25. data/lib/restful_objects/type_list.rb +30 -30
  26. data/lib/restful_objects/user.rb +30 -30
  27. data/lib/restful_objects/version.rb +1 -1
  28. data/spec/integration/domain-types_actions_spec.rb +43 -43
  29. data/spec/integration/domain-types_collections_spec.rb +45 -45
  30. data/spec/integration/domain-types_properties_spec.rb +41 -41
  31. data/spec/integration/server-root_spec.rb +98 -98
  32. data/spec/spec_helper.rb +52 -52
  33. data/spec/unit/object_actions_spec.rb +380 -380
  34. data/spec/unit/object_collections_spec.rb +190 -190
  35. data/spec/unit/object_properties_spec.rb +215 -206
  36. data/spec/unit/object_spec.rb +228 -228
  37. data/spec/unit/service_spec.rb +125 -125
  38. data/spec/unit/type_list_spec.rb +37 -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mE0ZTYwYzQ4
14
+ M2JiODdhMDRkNzFjYjgwNTQxN2Y0ODJmNTlhOTZjNTFjYTJlNWZmMmE2NjQ0
15
+ NGJkZThmMTNkNzRmNGI4Y2U5YzcyYjExYWMwYmE3NTlkNjdmM2Q=
data/README.md CHANGED
@@ -44,7 +44,8 @@ class Graph
44
44
  end
45
45
  end
46
46
  ```
47
-
47
+ You can check this example and more [here](https://github.com/vizcay/RestfulObjectsRubyExamples).
48
+
48
49
  ### How to install it?
49
50
  Run
50
51
 
@@ -64,7 +65,7 @@ to your's project Gemfile and 'bundle install' it.
64
65
  The source quality is at alpha state, and it was created mostly as a proof of concept. Still is has plenty of specs and a big percentage of the specification implemented, the grey areas are mostly related to errors and validations. It has been developed with MRI and hasn't been tested on other Ruby implementations.
65
66
 
66
67
  ### Dependencies
67
- - [Ruby 1.9.3 or higher](https://www.ruby-lang.org/‎)
68
+ - [Ruby 1.9.3 or higher](https://www.ruby-lang.org/)
68
69
  - [Sinatra](http://www.sinatrarb.com/)
69
70
  - [RSpec](http://rspec.info/)
70
71
  - [json_expressions](https://github.com/chancancode/json_expressions) for json testing.
File without changes
@@ -1,82 +1,96 @@
1
- module RestfulObjects
2
- class ActionDescription
3
- include LinkGenerator
4
-
5
- attr_reader :id, :kind_result_type, :result_type, :parameters
6
- attr_accessor :friendly_name, :description, :member_order, :disabled_reason
7
-
8
- def initialize(id, result_type, domain_type, parameters = {}, options = {})
9
- @id = id
10
-
11
- if result_type == :void
12
- result_type = [:void, :void]
13
- elsif result_type.is_a?(Symbol)
14
- result_type = [:scalar, result_type]
15
- end
16
- raise "result type should be a symbol or an array" if not result_type.is_a?(Array)
17
- raise "result type kind '#{result_type.last}' unssuported" if
18
- not [:void, :scalar, :object, :proto_object, :list].include?(result_type.first)
19
- @kind_result_type = result_type.first
20
- @result_type = result_type.last
21
- case @kind_result_type
22
- when :scalar
23
- raise "result type for scalar '#{result_type.last}' unssuported" if
24
- not [:string, :int, :decimal, :date, :blob].include?(@result_type)
25
- when :object, :proto_object, :list
26
- raise "result type should be a class or a string with a class name" if
27
- not (@result_type.is_a?(Class) || @result_type.is_a?(String))
28
- end
29
-
30
- @parameters = ParameterDescriptionList.new
31
- parameters.each { |name, definition| @parameters.add(name, definition) }
32
-
33
- @domain_type = domain_type
34
- @friendly_name = options[:friendly_name] || id
35
- @description = options[:description] || id
36
- @member_order = options[:member_order] || 0
37
- @disabled_reason = options[:disabled_reason] || ''
38
- end
39
-
40
- def get_representation
41
- representation = {
42
- 'id' => @id,
43
- 'hasParams' => has_params,
44
- 'memberOrder' => @member_order,
45
- 'parameters' => parameters_list,
46
- 'links' => [
47
- link_to(:self, "/domain-types/#{@domain_type}/actions/#{@id}", :action_description),
48
- link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
49
- link_to(:return_type, "/domain-types/#{result_type}", :domain_type)
50
- ],
51
- 'extensions' => {}
52
- }
53
-
54
- representation['friendlyName'] = friendly_name if friendly_name
55
- representation['description'] = description if description
56
-
57
- representation.to_json
58
- end
59
-
60
- def metadata
61
- result = { 'friendlyName' => friendly_name,
62
- 'description' => description,
63
- 'returnType' => result_type,
64
- 'hasParams' => has_params,
65
- 'memberOrder' => member_order }
66
- end
67
-
68
- def has_params
69
- not @parameters.empty?
70
- end
71
-
72
- def parameters_list
73
- result = {}
74
- parameters.each do |name, parameter|
75
- result[name] = {
76
- 'extension' => parameter.metadata
77
- }
78
- end
79
- result
80
- end
81
- end
82
- end
1
+ module RestfulObjects
2
+ class ActionDescription
3
+ include LinkGenerator
4
+
5
+ attr_reader :id, :kind_result_type, :result_type, :parameters
6
+ attr_accessor :friendly_name, :description, :member_order, :disabled_reason
7
+
8
+ def initialize(id, domain_type, options)
9
+ @id = id
10
+ @domain_type = domain_type
11
+ @friendly_name = options[:friendly_name] || id
12
+ @description = options[:description] || id
13
+ @member_order = options[:member_order] || 0
14
+ @disabled_reason = options[:disabled_reason] || ''
15
+
16
+ case options[:return_type]
17
+ when NilClass
18
+ @result_type = :void
19
+ @kind_result_type = :void
20
+ when Symbol
21
+ if options[:return_type] == :void
22
+ @result_type = :void
23
+ @kind_result_type = :void
24
+ else
25
+ raise "result type for scalar '#{options[:return_type]}' unssuported" unless [:string, :int, :bool, :decimal, :date, :blob].include?(options[:return_type])
26
+ @result_type = options[:return_type]
27
+ @kind_result_type = :scalar
28
+ end
29
+ when Hash
30
+ options[:return_type]
31
+ if options[:return_type][:object]
32
+ @result_type = options[:return_type][:object]
33
+ @kind_result_type = :object
34
+ elsif options[:return_type][:proto_object]
35
+ @result_type = options[:return_type][:proto_object]
36
+ @kind_result_type = :proto_object
37
+ elsif options[:return_type][:list]
38
+ @result_type = options[:return_type][:list]
39
+ @kind_result_type = :list
40
+ else
41
+ raise 'invalid return_type: object, proto_object or list key expected'
42
+ end
43
+ unless @result_type.is_a?(Class) or @result_type.is_a?(String)
44
+ raise 'return_type object, proto_object or list value should be a class or a string'
45
+ end
46
+ else
47
+ raise 'invalid return_type: symbol or hash expected'
48
+ end
49
+
50
+ @parameters = ParameterDescriptionList.new
51
+ options[:parameters].each { |name, definition| @parameters.add(name, definition) } if options[:parameters]
52
+ end
53
+
54
+ def get_representation
55
+ representation = {
56
+ 'id' => @id,
57
+ 'hasParams' => has_params,
58
+ 'memberOrder' => @member_order,
59
+ 'parameters' => parameters_list,
60
+ 'links' => [
61
+ link_to(:self, "/domain-types/#{@domain_type}/actions/#{@id}", :action_description),
62
+ link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
63
+ link_to(:return_type, "/domain-types/#{result_type}", :domain_type)
64
+ ],
65
+ 'extensions' => {}
66
+ }
67
+
68
+ representation['friendlyName'] = friendly_name if friendly_name
69
+ representation['description'] = description if description
70
+
71
+ representation.to_json
72
+ end
73
+
74
+ def metadata
75
+ result = { 'friendlyName' => friendly_name,
76
+ 'description' => description,
77
+ 'returnType' => result_type,
78
+ 'hasParams' => has_params,
79
+ 'memberOrder' => member_order }
80
+ end
81
+
82
+ def has_params
83
+ not @parameters.empty?
84
+ end
85
+
86
+ def parameters_list
87
+ result = {}
88
+ parameters.each do |name, parameter|
89
+ result[name] = {
90
+ 'extension' => parameter.metadata
91
+ }
92
+ end
93
+ result
94
+ end
95
+ end
96
+ end
@@ -1,17 +1,17 @@
1
- module RestfulObjects
2
- class ActionList
3
- extend Forwardable
4
-
5
- def initialize(domain_type)
6
- @actions = Hash.new
7
- @domain_type = domain_type
8
- end
9
-
10
- def add(id, result_type, parameters = {}, options = {})
11
- options[:member_order] ||= count + 1
12
- @actions[id] = ActionDescription.new(id, result_type, @domain_type, parameters, options)
13
- end
14
-
15
- def_delegators :@actions, :[], :each, :include?, :count, :empty?
16
- end
17
- end
1
+ module RestfulObjects
2
+ class ActionList
3
+ extend Forwardable
4
+
5
+ def initialize(domain_type)
6
+ @actions = Hash.new
7
+ @domain_type = domain_type
8
+ end
9
+
10
+ def add(id, options = {})
11
+ options[:member_order] ||= count + 1
12
+ @actions[id] = ActionDescription.new(id, @domain_type, options)
13
+ end
14
+
15
+ def_delegators :@actions, :[], :each, :include?, :count, :empty?
16
+ end
17
+ end
@@ -1,47 +1,47 @@
1
- module RestfulObjects
2
- class CollectionDescription
3
- include LinkGenerator
4
- attr_reader :id, :type, :read_only
5
- attr_accessor :friendly_name, :description, :plural_form, :member_order, :disabled_reason
6
-
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
-
32
- representation['friendlyName'] = friendly_name if friendly_name
33
- representation['description'] = description if description
34
-
35
- representation.to_json
36
- end
37
-
38
- def metadata
39
- { 'friendlyName' => friendly_name,
40
- 'description' => description,
41
- 'returnType' => 'list',
42
- 'elementType' => type,
43
- 'memberOrder' => member_order,
44
- 'pluralForm' => plural_form }
45
- end
46
- end
47
- end
1
+ module RestfulObjects
2
+ class CollectionDescription
3
+ include LinkGenerator
4
+ attr_reader :id, :type, :read_only
5
+ attr_accessor :friendly_name, :description, :plural_form, :member_order, :disabled_reason
6
+
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
+
32
+ representation['friendlyName'] = friendly_name if friendly_name
33
+ representation['description'] = description if description
34
+
35
+ representation.to_json
36
+ end
37
+
38
+ def metadata
39
+ { 'friendlyName' => friendly_name,
40
+ 'description' => description,
41
+ 'returnType' => 'list',
42
+ 'elementType' => type,
43
+ 'memberOrder' => member_order,
44
+ 'pluralForm' => plural_form }
45
+ end
46
+ end
47
+ end
@@ -1,17 +1,17 @@
1
- module RestfulObjects
2
- class CollectionList
3
- extend Forwardable
4
-
5
- def initialize(domain_type)
6
- @domain_type = domain_type
7
- @collections = Hash.new
8
- end
9
-
10
- def add(name, type, options = {})
11
- options[:member_order] ||= count + 1
12
- @collections[name] = CollectionDescription.new(name, type, @domain_type, options)
13
- end
14
-
15
- def_delegators :@collections, :[], :each, :each_key, :each_value, :include?, :count, :empty?, :clear
16
- end
17
- end
1
+ module RestfulObjects
2
+ class CollectionList
3
+ extend Forwardable
4
+
5
+ def initialize(domain_type)
6
+ @domain_type = domain_type
7
+ @collections = Hash.new
8
+ end
9
+
10
+ def add(name, type, options = {})
11
+ options[:member_order] ||= count + 1
12
+ @collections[name] = CollectionDescription.new(name, type, @domain_type, options)
13
+ end
14
+
15
+ def_delegators :@collections, :[], :each, :each_key, :each_value, :include?, :count, :empty?, :clear
16
+ end
17
+ end
@@ -1,79 +1,83 @@
1
- module RestfulObjects
2
- class DomainModel
3
- include LinkGenerator
4
-
5
- attr_accessor :base_url, :compatible_mode
6
- attr_reader :metadata_schema, :version, :user, :types, :services, :objects
7
-
8
- def self.current
9
- @current ||= DomainModel.new
10
- end
11
-
12
- def self.current=(value)
13
- @current = value
14
- end
15
-
16
- def initialize
17
- @base_url = 'http://localhost'
18
- @metadata_schema = :selectable
19
- @compatible_mode = false
20
- @user = User.new(@base_url, 'anonymous')
21
- @types = TypeList.new
22
- @services = ServiceList.new(@base_url)
23
- @objects = ObjectList.new(@base_url)
24
- end
25
-
26
- def get_homepage
27
- { 'links' => [
28
- link_to(:self, '/', :homepage),
29
- link_to(:user, '/user', :user),
30
- link_to(:services, '/services', :list),
31
- link_to(:version, '/version', :version),
32
- link_to(:domain_types, '/domain-types', :type_list)
33
- ],
34
- 'extensions' => {}
35
- }.to_json
36
- end
37
-
38
- def get_version
39
- { 'links' => [
40
- link_to(:self, '/version', :version),
41
- link_to(:up, '/', :homepage),
42
- ],
43
- 'specVersion' => '1.0',
44
- 'optionalCapabilities' => {
45
- 'blobsClobs' => true,
46
- 'deleteObjects' => true,
47
- 'domainModel' => metadata_schema.to_s,
48
- 'protoPersistentObjects' => true,
49
- 'validateOnly' => false
50
- },
51
- 'extensions' => {}
52
- }.to_json
53
- end
54
-
55
- def get_user
56
- @user.get_as_json
57
- end
58
-
59
- def get_services
60
- services.get_list
61
- end
62
-
63
- def metadata_schema=(value)
64
- if not [:simple, :formal, :selectable].include?(value)
65
- raise "invalid metadata schema, choose :simple, :formal or :selectable"
66
- end
67
- @metadata_schema = value
68
- end
69
-
70
- def reset
71
- @base_url = 'http://localhost'
72
- @user = nil
73
- @types.clear
74
- @services.clear
75
- @objects.clear
76
- end
77
- end
78
- end
79
-
1
+ module RestfulObjects
2
+ class DomainModel
3
+ include LinkGenerator
4
+
5
+ attr_accessor :base_url, :compatible_mode
6
+ attr_reader :metadata_schema, :version, :user, :types, :services, :objects
7
+
8
+ def self.current
9
+ @current ||= DomainModel.new
10
+ end
11
+
12
+ def self.current=(value)
13
+ @current = value
14
+ end
15
+
16
+ def initialize
17
+ @base_url = 'http://localhost'
18
+ @metadata_schema = :selectable
19
+ @compatible_mode = false
20
+ @user = User.new(@base_url, 'anonymous')
21
+ @types = TypeList.new
22
+ @services = ServiceList.new(@base_url)
23
+ @objects = ObjectList.new(@base_url)
24
+ end
25
+
26
+ def get_homepage
27
+ { 'links' => [
28
+ link_to(:self, '/', :homepage),
29
+ link_to(:user, '/user', :user),
30
+ link_to(:services, '/services', :list),
31
+ link_to(:version, '/version', :version),
32
+ link_to(:domain_types, '/domain-types', :type_list)
33
+ ],
34
+ 'extensions' => {}
35
+ }.to_json
36
+ end
37
+
38
+ def get_version
39
+ { 'links' => [
40
+ link_to(:self, '/version', :version),
41
+ link_to(:up, '/', :homepage),
42
+ ],
43
+ 'specVersion' => '1.0',
44
+ 'optionalCapabilities' => {
45
+ 'blobsClobs' => true,
46
+ 'deleteObjects' => true,
47
+ 'domainModel' => metadata_schema.to_s,
48
+ 'protoPersistentObjects' => true,
49
+ 'validateOnly' => false
50
+ },
51
+ 'extensions' => {}
52
+ }.to_json
53
+ end
54
+
55
+ def get_user
56
+ @user.get_as_json
57
+ end
58
+
59
+ def get_services
60
+ services.get_list
61
+ end
62
+
63
+ def metadata_schema=(value)
64
+ if not [:simple, :formal, :selectable].include?(value)
65
+ raise "invalid metadata schema, choose :simple, :formal or :selectable"
66
+ end
67
+ @metadata_schema = value
68
+ end
69
+
70
+ def reset
71
+ @base_url = 'http://localhost'
72
+ @user = nil
73
+ @types.clear
74
+ @services.clear
75
+ @objects.clear
76
+ end
77
+
78
+ def reset_objects
79
+ @objects.clear
80
+ end
81
+ end
82
+ end
83
+