Class: RestfulObjects::DomainModel
- Inherits:
-
Object
- Object
- RestfulObjects::DomainModel
- Includes:
- LinkGenerator
- Defined in:
- lib/restful_objects/domain_model/domain_model.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#compatible_mode ⇒ Object
Returns the value of attribute compatible_mode.
-
#metadata_schema ⇒ Object
Returns the value of attribute metadata_schema.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #get_homepage ⇒ Object
- #get_services ⇒ Object
- #get_type_list_representation ⇒ Object
- #get_user ⇒ Object
- #get_version ⇒ Object
-
#initialize ⇒ DomainModel
constructor
A new instance of DomainModel.
- #register_object(instance) ⇒ Object
- #register_service(service) ⇒ Object
- #register_type(name) ⇒ Object
- #reset ⇒ Object
- #reset_objects ⇒ Object
Methods included from LinkGenerator
#generate_rel, #generate_repr_type, #link_to, #underscore_to_hyphen_string
Constructor Details
#initialize ⇒ DomainModel
Returns a new instance of DomainModel.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 22 def initialize @base_url = 'http://localhost' = :selectable @compatible_mode = false @user = User.new(@base_url, 'anonymous') @types = {} @services = {} @objects = {} @services.instance_eval do alias :base_accesor :[] def [](key) value = base_accesor(key) if value.is_a?(Class) value = value.new self[key] = value end value end end end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
11 12 13 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 11 def base_url @base_url end |
#compatible_mode ⇒ Object
Returns the value of attribute compatible_mode.
11 12 13 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 11 def compatible_mode @compatible_mode end |
#metadata_schema ⇒ Object
Returns the value of attribute metadata_schema.
12 13 14 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 12 def end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
12 13 14 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 12 def objects @objects end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
12 13 14 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 12 def services @services end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
12 13 14 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 12 def types @types end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
12 13 14 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 12 def user @user end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
12 13 14 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 12 def version @version end |
Class Method Details
.current ⇒ Object
14 15 16 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 14 def self.current @current ||= DomainModel.new end |
.current=(value) ⇒ Object
18 19 20 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 18 def self.current=(value) @current = value end |
Instance Method Details
#get_homepage ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 57 def get_homepage { 'links' => [ link_to(:self, '/', :homepage), link_to(:user, '/user', :user), link_to(:services, '/services', :list), link_to(:version, '/version', :version), link_to(:domain_types, '/domain-types', :type_list) ], 'extensions' => {} }.to_json end |
#get_services ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 90 def get_services { 'links' => [ link_to(:self, '/services', :services), link_to(:up, '/', :homepage), ], 'value' => services_generate_values, 'extensions' => { } }.to_json end |
#get_type_list_representation ⇒ Object
100 101 102 103 104 105 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 100 def get_type_list_representation { 'value' => @types.each_value.map { |type| link_to(:domain_type, "/domain-types/#{type.id}", :domain_type) }, 'links' => [link_to(:self, '/domain-types', :type_list), link_to(:up, '/', :homepage)] }.to_json end |
#get_user ⇒ Object
86 87 88 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 86 def get_user @user.get_as_json end |
#get_version ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 69 def get_version { 'links' => [ link_to(:self, '/version', :version), link_to(:up, '/', :homepage), ], 'specVersion' => '1.0', 'optionalCapabilities' => { 'blobsClobs' => true, 'deleteObjects' => true, 'domainModel' => .to_s, 'protoPersistentObjects' => true, 'validateOnly' => false }, 'extensions' => {} }.to_json end |
#register_object(instance) ⇒ Object
44 45 46 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 44 def register_object(instance) @objects[instance.object_id] = instance end |
#register_service(service) ⇒ Object
48 49 50 51 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 48 def register_service(service) raise 'service registration should be done with a class' unless service.is_a?(Class) @services[service.name] = service end |
#register_type(name) ⇒ Object
53 54 55 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 53 def register_type(name) @types[name] = DomainType.new(name) end |
#reset ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 114 def reset @base_url = 'http://localhost' @user = nil @types.clear @services.clear @objects.clear end |
#reset_objects ⇒ Object
122 123 124 |
# File 'lib/restful_objects/domain_model/domain_model.rb', line 122 def reset_objects @objects.clear end |