restful_objects 0.0.2 → 0.0.3
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 +8 -8
- data/README.md +3 -2
- data/bin/restful_server.rb +0 -0
- data/lib/restful_objects/action_description.rb +96 -82
- data/lib/restful_objects/action_list.rb +17 -17
- data/lib/restful_objects/collection_description.rb +47 -47
- data/lib/restful_objects/collection_list.rb +17 -17
- data/lib/restful_objects/domain_model.rb +83 -79
- data/lib/restful_objects/http_response.rb +11 -11
- data/lib/restful_objects/link_generator.rb +104 -104
- data/lib/restful_objects/object.rb +20 -20
- data/lib/restful_objects/object_actions.rb +134 -134
- data/lib/restful_objects/object_base.rb +10 -0
- data/lib/restful_objects/object_collections.rb +84 -84
- data/lib/restful_objects/object_list.rb +16 -16
- data/lib/restful_objects/object_macros.rb +35 -35
- data/lib/restful_objects/object_properties.rb +78 -78
- data/lib/restful_objects/parameter_description.rb +60 -60
- data/lib/restful_objects/parameter_description_list.rb +15 -15
- data/lib/restful_objects/property_description.rb +68 -68
- data/lib/restful_objects/property_list.rb +17 -17
- data/lib/restful_objects/service.rb +21 -21
- data/lib/restful_objects/service_list.rb +55 -55
- data/lib/restful_objects/type.rb +110 -110
- data/lib/restful_objects/type_list.rb +30 -30
- data/lib/restful_objects/user.rb +30 -30
- data/lib/restful_objects/version.rb +1 -1
- data/spec/integration/domain-types_actions_spec.rb +43 -43
- data/spec/integration/domain-types_collections_spec.rb +45 -45
- data/spec/integration/domain-types_properties_spec.rb +41 -41
- data/spec/integration/server-root_spec.rb +98 -98
- data/spec/spec_helper.rb +52 -52
- data/spec/unit/object_actions_spec.rb +380 -380
- data/spec/unit/object_collections_spec.rb +190 -190
- data/spec/unit/object_properties_spec.rb +215 -206
- data/spec/unit/object_spec.rb +228 -228
- data/spec/unit/service_spec.rb +125 -125
- data/spec/unit/type_list_spec.rb +37 -37
- metadata +2 -2
@@ -1,60 +1,60 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
class ParameterDescription
|
3
|
-
include LinkGenerator
|
4
|
-
|
5
|
-
attr_reader :id, :name, :number, :kind_type, :type
|
6
|
-
attr_accessor :friendly_name, :description, :optional, :max_length, :pattern, :format
|
7
|
-
|
8
|
-
def initialize(id, definition, number)
|
9
|
-
@id = id
|
10
|
-
@name = id
|
11
|
-
|
12
|
-
if definition.is_a? Array # [type, options]
|
13
|
-
if [:string, :int, :decimal, :date, :blob].include?(definition.first) # scalar
|
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
|
27
|
-
@kind_type = :scalar
|
28
|
-
@type = definition
|
29
|
-
raise "result type for scalar '#{@type}' unssuported" if not [:string, :int, :decimal, :date, :blob].include?(@type)
|
30
|
-
elsif definition.is_a? String # object type
|
31
|
-
@kind_type = :object
|
32
|
-
@type = definition
|
33
|
-
elsif definition.is_a? Class # object type
|
34
|
-
@kind_type = :object
|
35
|
-
@type = definition.to_s
|
36
|
-
else
|
37
|
-
raise "unssuported parameter definition type #{definition.class}"
|
38
|
-
end
|
39
|
-
|
40
|
-
options ||= {}
|
41
|
-
@number = options[:number] || number
|
42
|
-
@friendly_name = options[:friendly_name] || id
|
43
|
-
@description = options[:description] || id
|
44
|
-
@optional = options[:optional].nil? ? true : options[:optional]
|
45
|
-
@max_length = options[:max_length]
|
46
|
-
@pattern = options[:pattern]
|
47
|
-
end
|
48
|
-
|
49
|
-
def metadata
|
50
|
-
result = { 'friendlyName' => friendly_name,
|
51
|
-
'description' => description,
|
52
|
-
'optional' => optional,
|
53
|
-
'returnType' => type }
|
54
|
-
result['maxLength'] = max_length if max_length
|
55
|
-
result['pattern'] = pattern if pattern
|
56
|
-
result['format'] = format if format
|
57
|
-
result
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
module RestfulObjects
|
2
|
+
class ParameterDescription
|
3
|
+
include LinkGenerator
|
4
|
+
|
5
|
+
attr_reader :id, :name, :number, :kind_type, :type
|
6
|
+
attr_accessor :friendly_name, :description, :optional, :max_length, :pattern, :format
|
7
|
+
|
8
|
+
def initialize(id, definition, number)
|
9
|
+
@id = id
|
10
|
+
@name = id
|
11
|
+
|
12
|
+
if definition.is_a? Array # [type, options]
|
13
|
+
if [:string, :int, :decimal, :date, :blob].include?(definition.first) # scalar
|
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
|
27
|
+
@kind_type = :scalar
|
28
|
+
@type = definition
|
29
|
+
raise "result type for scalar '#{@type}' unssuported" if not [:string, :int, :decimal, :date, :blob].include?(@type)
|
30
|
+
elsif definition.is_a? String # object type
|
31
|
+
@kind_type = :object
|
32
|
+
@type = definition
|
33
|
+
elsif definition.is_a? Class # object type
|
34
|
+
@kind_type = :object
|
35
|
+
@type = definition.to_s
|
36
|
+
else
|
37
|
+
raise "unssuported parameter definition type #{definition.class}"
|
38
|
+
end
|
39
|
+
|
40
|
+
options ||= {}
|
41
|
+
@number = options[:number] || number
|
42
|
+
@friendly_name = options[:friendly_name] || id
|
43
|
+
@description = options[:description] || id
|
44
|
+
@optional = options[:optional].nil? ? true : options[:optional]
|
45
|
+
@max_length = options[:max_length]
|
46
|
+
@pattern = options[:pattern]
|
47
|
+
end
|
48
|
+
|
49
|
+
def metadata
|
50
|
+
result = { 'friendlyName' => friendly_name,
|
51
|
+
'description' => description,
|
52
|
+
'optional' => optional,
|
53
|
+
'returnType' => type }
|
54
|
+
result['maxLength'] = max_length if max_length
|
55
|
+
result['pattern'] = pattern if pattern
|
56
|
+
result['format'] = format if format
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
class ParameterDescriptionList
|
3
|
-
extend Forwardable
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@parameters = Hash.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def add(id, definition)
|
10
|
-
@parameters[id] = ParameterDescription.new(id, definition, count + 1)
|
11
|
-
end
|
12
|
-
|
13
|
-
def_delegators :@parameters, :[], :each, :include?, :count, :empty?
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module RestfulObjects
|
2
|
+
class ParameterDescriptionList
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@parameters = Hash.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(id, definition)
|
10
|
+
@parameters[id] = ParameterDescription.new(id, definition, count + 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
def_delegators :@parameters, :[], :each, :include?, :count, :empty?
|
14
|
+
end
|
15
|
+
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
class PropertyDescription
|
3
|
-
include LinkGenerator
|
4
|
-
|
5
|
-
attr_accessor :id, :domain_type, :return_type, :friendly_name, :description, :optional, :read_only, :member_order,
|
6
|
-
:max_length, :disabled_reason, :pattern
|
7
|
-
|
8
|
-
def initialize(id, domain_type, return_type, options)
|
9
|
-
raise "property type #{return_type} usupported" if not [:string, :int, :decimal, :date, :blob].include?(return_type)
|
10
|
-
|
11
|
-
@id = id
|
12
|
-
@domain_type = domain_type
|
13
|
-
@return_type = return_type
|
14
|
-
@friendly_name = options[:friendly_name] || id
|
15
|
-
@description = options[:description] || id
|
16
|
-
@optional = options[:optional].nil? ? true : options[:optional]
|
17
|
-
@read_only = options[:read_only].nil? ? false : options[:read_only]
|
18
|
-
@member_order = options[:member_order] || 1
|
19
|
-
@max_length = options[:max_length]
|
20
|
-
@disabled_reason = options[:disabled_reason] || 'read-only property' if read_only
|
21
|
-
@pattern = options[:pattern]
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_representation
|
25
|
-
representation = {
|
26
|
-
'id' => @id,
|
27
|
-
'optional' => optional,
|
28
|
-
'memberOrder' => @member_order,
|
29
|
-
'links' => [
|
30
|
-
link_to(:self, "/domain-types/#{@domain_type}/properties/#{@id}", :property_description),
|
31
|
-
link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
|
32
|
-
link_to(:return_type, "/domain-types/#{@return_type}", :domain_type)
|
33
|
-
],
|
34
|
-
'extensions' => {}
|
35
|
-
}
|
36
|
-
|
37
|
-
representation['friendlyName'] = friendly_name if friendly_name
|
38
|
-
representation['description'] = description if description
|
39
|
-
|
40
|
-
representation.to_json
|
41
|
-
end
|
42
|
-
|
43
|
-
def metadata
|
44
|
-
result = { 'friendlyName' => friendly_name,
|
45
|
-
'description' => description,
|
46
|
-
'returnType' => return_type,
|
47
|
-
'format' => format,
|
48
|
-
'optional' => optional,
|
49
|
-
'memberOrder' => member_order }
|
50
|
-
result['maxLength'] = max_length if max_length
|
51
|
-
result['pattern'] = pattern if pattern
|
52
|
-
result
|
53
|
-
end
|
54
|
-
|
55
|
-
def format
|
56
|
-
case return_type
|
57
|
-
when :string
|
58
|
-
'string'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def get_value_as_json
|
63
|
-
{ 'id' =>
|
64
|
-
{ 'value' => '' }
|
65
|
-
}.to_json
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
module RestfulObjects
|
2
|
+
class PropertyDescription
|
3
|
+
include LinkGenerator
|
4
|
+
|
5
|
+
attr_accessor :id, :domain_type, :return_type, :friendly_name, :description, :optional, :read_only, :member_order,
|
6
|
+
:max_length, :disabled_reason, :pattern
|
7
|
+
|
8
|
+
def initialize(id, domain_type, return_type, options)
|
9
|
+
raise "property type #{return_type} usupported" if not [:string, :int, :bool, :decimal, :date, :blob].include?(return_type)
|
10
|
+
|
11
|
+
@id = id
|
12
|
+
@domain_type = domain_type
|
13
|
+
@return_type = return_type
|
14
|
+
@friendly_name = options[:friendly_name] || id
|
15
|
+
@description = options[:description] || id
|
16
|
+
@optional = options[:optional].nil? ? true : options[:optional]
|
17
|
+
@read_only = options[:read_only].nil? ? false : options[:read_only]
|
18
|
+
@member_order = options[:member_order] || 1
|
19
|
+
@max_length = options[:max_length]
|
20
|
+
@disabled_reason = options[:disabled_reason] || 'read-only property' if read_only
|
21
|
+
@pattern = options[:pattern]
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_representation
|
25
|
+
representation = {
|
26
|
+
'id' => @id,
|
27
|
+
'optional' => optional,
|
28
|
+
'memberOrder' => @member_order,
|
29
|
+
'links' => [
|
30
|
+
link_to(:self, "/domain-types/#{@domain_type}/properties/#{@id}", :property_description),
|
31
|
+
link_to(:up, "/domain-types/#{@domain_type}", :domain_type),
|
32
|
+
link_to(:return_type, "/domain-types/#{@return_type}", :domain_type)
|
33
|
+
],
|
34
|
+
'extensions' => {}
|
35
|
+
}
|
36
|
+
|
37
|
+
representation['friendlyName'] = friendly_name if friendly_name
|
38
|
+
representation['description'] = description if description
|
39
|
+
|
40
|
+
representation.to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def metadata
|
44
|
+
result = { 'friendlyName' => friendly_name,
|
45
|
+
'description' => description,
|
46
|
+
'returnType' => return_type,
|
47
|
+
'format' => format,
|
48
|
+
'optional' => optional,
|
49
|
+
'memberOrder' => member_order }
|
50
|
+
result['maxLength'] = max_length if max_length
|
51
|
+
result['pattern'] = pattern if pattern
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
55
|
+
def format
|
56
|
+
case return_type
|
57
|
+
when :string
|
58
|
+
'string'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_value_as_json
|
63
|
+
{ 'id' =>
|
64
|
+
{ 'value' => '' }
|
65
|
+
}.to_json
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
class PropertyList
|
3
|
-
extend Forwardable
|
4
|
-
|
5
|
-
def initialize(domain_type)
|
6
|
-
@properties = Hash.new
|
7
|
-
@domain_type = domain_type
|
8
|
-
end
|
9
|
-
|
10
|
-
def add(id, return_type, options = {})
|
11
|
-
options[:member_order] ||= count + 1
|
12
|
-
@properties[id] = PropertyDescription.new(id, @domain_type, return_type, options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def_delegators :@properties, :[], :each, :include?, :count, :empty?
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module RestfulObjects
|
2
|
+
class PropertyList
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def initialize(domain_type)
|
6
|
+
@properties = Hash.new
|
7
|
+
@domain_type = domain_type
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(id, return_type, options = {})
|
11
|
+
options[:member_order] ||= count + 1
|
12
|
+
@properties[id] = PropertyDescription.new(id, @domain_type, return_type, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def_delegators :@properties, :[], :each, :include?, :count, :empty?
|
16
|
+
end
|
17
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
module Service
|
3
|
-
include LinkGenerator
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
RestfulObjects::DomainModel.current.types.add(base.name)
|
7
|
-
|
8
|
-
base.class_eval do
|
9
|
-
extend ObjectMacros
|
10
|
-
include ObjectBase
|
11
|
-
include ObjectActions
|
12
|
-
|
13
|
-
def rs_register_in_model
|
14
|
-
# do_nothing
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
RestfulObjects::DomainModel.current.services.register(base)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module RestfulObjects
|
2
|
+
module Service
|
3
|
+
include LinkGenerator
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
RestfulObjects::DomainModel.current.types.add(base.name)
|
7
|
+
|
8
|
+
base.class_eval do
|
9
|
+
extend ObjectMacros
|
10
|
+
include ObjectBase
|
11
|
+
include ObjectActions
|
12
|
+
|
13
|
+
def rs_register_in_model
|
14
|
+
# do_nothing
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RestfulObjects::DomainModel.current.services.register(base)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
class ServiceList
|
3
|
-
extend Forwardable
|
4
|
-
include LinkGenerator
|
5
|
-
|
6
|
-
def initialize(base_url)
|
7
|
-
@services = Hash.new
|
8
|
-
@base_url = base_url
|
9
|
-
end
|
10
|
-
|
11
|
-
def register(service)
|
12
|
-
raise 'service registration should be done with a class' if not service.is_a? Class
|
13
|
-
@services[service.name] = service
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_list
|
17
|
-
representation = {
|
18
|
-
'links' => [
|
19
|
-
link_to(:self, '/services', :services),
|
20
|
-
link_to(:up, '/', :homepage),
|
21
|
-
],
|
22
|
-
'value' => generate_values,
|
23
|
-
'extensions' => { }
|
24
|
-
}.to_json
|
25
|
-
end
|
26
|
-
|
27
|
-
def [](key)
|
28
|
-
value = @services[key]
|
29
|
-
if value.is_a? Class
|
30
|
-
value = value.new
|
31
|
-
@services[key] = value
|
32
|
-
end
|
33
|
-
value
|
34
|
-
end
|
35
|
-
|
36
|
-
def_delegators :@services, :each, :include?, :count, :empty?, :clear
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def generate_values
|
41
|
-
ensure_all_created
|
42
|
-
values = []
|
43
|
-
each do |name, service|
|
44
|
-
element = link_to(:service, "/services/#{name}", :object, service_id: name)
|
45
|
-
element['title'] = service.title
|
46
|
-
values << element
|
47
|
-
end
|
48
|
-
values
|
49
|
-
end
|
50
|
-
|
51
|
-
def ensure_all_created
|
52
|
-
@services.each { |name, value| @services[name] = value.new if value.is_a? Class }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
module RestfulObjects
|
2
|
+
class ServiceList
|
3
|
+
extend Forwardable
|
4
|
+
include LinkGenerator
|
5
|
+
|
6
|
+
def initialize(base_url)
|
7
|
+
@services = Hash.new
|
8
|
+
@base_url = base_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def register(service)
|
12
|
+
raise 'service registration should be done with a class' if not service.is_a? Class
|
13
|
+
@services[service.name] = service
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_list
|
17
|
+
representation = {
|
18
|
+
'links' => [
|
19
|
+
link_to(:self, '/services', :services),
|
20
|
+
link_to(:up, '/', :homepage),
|
21
|
+
],
|
22
|
+
'value' => generate_values,
|
23
|
+
'extensions' => { }
|
24
|
+
}.to_json
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
value = @services[key]
|
29
|
+
if value.is_a? Class
|
30
|
+
value = value.new
|
31
|
+
@services[key] = value
|
32
|
+
end
|
33
|
+
value
|
34
|
+
end
|
35
|
+
|
36
|
+
def_delegators :@services, :each, :include?, :count, :empty?, :clear
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def generate_values
|
41
|
+
ensure_all_created
|
42
|
+
values = []
|
43
|
+
each do |name, service|
|
44
|
+
element = link_to(:service, "/services/#{name}", :object, service_id: name)
|
45
|
+
element['title'] = service.title
|
46
|
+
values << element
|
47
|
+
end
|
48
|
+
values
|
49
|
+
end
|
50
|
+
|
51
|
+
def ensure_all_created
|
52
|
+
@services.each { |name, value| @services[name] = value.new if value.is_a? Class }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|