Class: Scrivito::BasicObj
- Inherits:
-
Object
- Object
- Scrivito::BasicObj
- Defined in:
- lib/fiona7/scrivito_patches/basic_obj.rb
Direct Known Subclasses
Class Method Summary collapse
-
.all ⇒ Object
Originally this method refers to the global Obj via ::Obj and does not support shadow classes.
- .inherited(subclass, *args) ⇒ Object
-
.type_computer ⇒ Object
Type computer computes with global Obj by default which in legacy mode belongs to fiona_connector Therefore we limit the scope of the search to Scrivito::Obj.
-
.where(field, operator, value, boost = nil) ⇒ Object
Originally this method refers to the global Obj via ::Obj and does not support shadow classes.
Instance Method Summary collapse
-
#assert_revertable ⇒ Object
Patch to allow reverting in rtc workspace.
-
#copy_binaries(attributes) ⇒ Object
Original implementation mishandles attribute => [type, value].
-
#copy_binary(destination_obj_id, binary) ⇒ Object
Original implmentation uses the blob copy API This is completely unneccessary, as the required logic is already possible implemented similar to FutureBinary.
-
#file_extension ⇒ Object
Original implentation reads file extension from name but since dots are not allowed in the names it has to be worked around.
- #fiona_obj ⇒ Object
-
#outdated? ⇒ Boolean
optimized away.
-
#publishable? ⇒ Boolean
Originally this method checks for conflicts which are impossible here, hence the method is stubbed out.
-
#transfer_modifications_to(target_workspace) ⇒ Object
optimized away.
Class Method Details
.all ⇒ Object
Originally this method refers to the global Obj via ::Obj and does not support shadow classes
98 99 100 101 102 103 104 105 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 98 def self.all assert_not_basic_obj('.all') if self == ::Obj || self == Obj Workspace.current.objs.all else find_all_by_obj_class(to_s) end end |
.inherited(subclass, *args) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 109 def inherited(subclass,*args) super # Under certain condition a circular dependency may arise in rails when # loading classes, especially when eager_load = true # Thusfar it has only been observed in standalone-mode thus far: # Loading Obj < Scrivito::BasicObj triggers this hook # which tries to set RailsConnector::Obj to a reasonable value, # RailsConnector::AbstractObj provided by reactor. # RailsConnector::AbstractObj tries set itself to couple of # values, one of which is ::Obj # If this occurs with eager_load = true Rails may get confused # and trigger circular dependency error. # We work around this problem by hijacking intelligent initialization # of RailsConnector::AbstractObj in reactor and set it to a # desired value ourselves. if subclass.name == 'Obj' && !::RailsConnector.const_defined?('AbstractObj', false) ::RailsConnector.const_set('AbstractObj', ::RailsConnector::BasicObj) end if subclass.name == 'Obj' && !::RailsConnector.const_defined?('Obj', false) ::RailsConnector.const_set('Obj', ::RailsConnector::AbstractObj) end ensure if subclass.name.present? subclass.register_attribute_definitions(subclass.to_s) end end |
.type_computer ⇒ Object
Type computer computes with global Obj by default which in legacy mode belongs to fiona_connector Therefore we limit the scope of the search to Scrivito::Obj
8 9 10 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 8 def self.type_computer @_type_computer ||= TypeComputer.new(Scrivito::BasicObj, Obj) end |
.where(field, operator, value, boost = nil) ⇒ Object
Originally this method refers to the global Obj via ::Obj and does not support shadow classes
86 87 88 89 90 91 92 93 94 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 86 def self.where(field, operator, value, boost = nil) assert_not_basic_obj('.where') if self == ::Obj || self == Obj Workspace.current.objs.where(field, operator, value, boost) else Workspace.current.objs.where(:_obj_class, :equals, to_s) .and(field, operator, value, boost) end end |
Instance Method Details
#assert_revertable ⇒ Object
Patch to allow reverting in rtc workspace
75 76 77 78 79 80 81 82 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 75 def assert_revertable if workspace.id != 'rtc' raise ScrivitoError, "cannot revert changes, since obj is not from valid revertable workspace." end if modification == Modification::NEW || modification == Modification::DELETED raise ScrivitoError, "cannot revert changes, since obj is #{modification}." end end |
#copy_binaries(attributes) ⇒ Object
Original implementation mishandles attribute => [type, value]
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 44 def copy_binaries(attributes) attribute_defintions = self.class.find_attribute_definitions(obj_class) destination_obj_id = attributes.fetch(:_id) Hash[attributes.map do |name, value| # Here is the change if value && attribute_defintions[name].try(:type) == 'binary' && (binary = self[name]) [name, ['binary', copy_binary(destination_obj_id, binary)]] else [name, value] end end] end |
#copy_binary(destination_obj_id, binary) ⇒ Object
Original implmentation uses the blob copy API This is completely unneccessary, as the required logic is already possible implemented similar to FutureBinary
61 62 63 64 65 66 67 68 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 61 def copy_binary(destination_obj_id, binary) { obj_id: destination_obj_id, id_to_copy: binary.id, filename: binary.filename, content_type: binary.content_type }.stringify_keys end |
#file_extension ⇒ Object
Original implentation reads file extension from name but since dots are not allowed in the names it has to be worked around.
35 36 37 38 39 40 41 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 35 def file_extension if (blob = find_blob) File.extname(blob.filename)[1..-1] else "" end end |
#fiona_obj ⇒ Object
70 71 72 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 70 def fiona_obj @fiona_obj ||= ::RailsConnector::BasicObj.find(self.id) end |
#outdated? ⇒ Boolean
optimized away
13 14 15 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 13 def outdated? false end |
#publishable? ⇒ Boolean
Originally this method checks for conflicts which are impossible here, hence the method is stubbed out
26 27 28 29 30 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 26 def publishable? # TODO: implement CM validations here # FIXME: this can be solved much faster in PublishChecker self.id && Fiona7::EditedObj.find(self.id)..release? end |
#transfer_modifications_to(target_workspace) ⇒ Object
optimized away
18 19 20 21 22 |
# File 'lib/fiona7/scrivito_patches/basic_obj.rb', line 18 def transfer_modifications_to(target_workspace) return unless modification raise TransferModificationsModifiedError, "Already modified in workspace #{target_workspace.id}" end |