Module: Reactor::Attributes::Base

Defined in:
lib/reactor/attributes.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



180
181
182
183
# File 'lib/reactor/attributes.rb', line 180

def self.included(base)
  base.extend(ClassMethods)
  Reactor::Attributes::LinkListExtender.extend_linklist!
end

Instance Method Details

#blobObject



209
210
211
212
213
214
215
# File 'lib/reactor/attributes.rb', line 209

def blob
  if attr_dict.respond_to?(:blob)
    attr_dict.send :blob
  else
    nil
  end
end

#blob=(value) ⇒ Object



217
218
219
# File 'lib/reactor/attributes.rb', line 217

def blob=(value)
  set(:blob, value)
end

#body=(value) ⇒ Object



205
206
207
# File 'lib/reactor/attributes.rb', line 205

def body=(value)
  set(:body, value)
end

#body_changed?Boolean

Returns:

  • (Boolean)


237
238
239
# File 'lib/reactor/attributes.rb', line 237

def body_changed?
  attribute_changed?(:body)
end

#channelsObject



233
234
235
# File 'lib/reactor/attributes.rb', line 233

def channels
  self[:channels] || []
end

#channels=(value) ⇒ Object



225
226
227
# File 'lib/reactor/attributes.rb', line 225

def channels=(value)
  set(:channels, value)
end

#channels_changed?Boolean

Returns:

  • (Boolean)


245
246
247
# File 'lib/reactor/attributes.rb', line 245

def channels_changed?
  attribute_changed?(:channels)
end

#name=(value) ⇒ Object



201
202
203
# File 'lib/reactor/attributes.rb', line 201

def name=(value)
  set(:name, value)
end

#obj_class=(value) ⇒ Object



193
194
195
# File 'lib/reactor/attributes.rb', line 193

def obj_class=(value)
  set(:obj_class, value)
end

#permalink=(value) ⇒ Object



197
198
199
# File 'lib/reactor/attributes.rb', line 197

def permalink=(value)
  set(:permalink, value)
end

#reload_attributes(new_obj_class = nil) ⇒ Object



299
300
301
302
303
# File 'lib/reactor/attributes.rb', line 299

def reload_attributes(new_obj_class=nil)
  new_obj_class = new_obj_class || self.obj_class
  RailsConnector::Meta::EagerLoader.instance.forget_obj_class(new_obj_class)
  Reactor::AttributeHandlers.reinstall_attributes(self.singleton_class, new_obj_class)
end

#set(key, value, options = {}) ⇒ Object

Note:

options are passed to underlying xml interface, but as of now have no effect

Sets given attribute, to given value. Converts values if neccessary

Raises:

  • (TypeError)

See Also:

  • Reactor::Attributes::Base.[Reactor[Reactor::Attributes]


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/reactor/attributes.rb', line 252

def set(key, value, options={})
  key = key.to_sym
  raise TypeError, "can't modify frozen object" if frozen?
  key = resolve_attribute_alias(key)
  raise ArgumentError, "Unknown attribute #{key.to_s} for #{self.class.to_s} #{self.path}" unless allowed_attr?(key)
  attr = key_to_attr(key)

  not_formated_value = value
  formated_value = serialize_value(key, value)
  crul_set(attr, formated_value, options)

  __track_dirty_attribute(key)
  active_record_set(key, formated_value) if active_record_attr?(key)
  rails_connector_set(key, formated_value, not_formated_value)

  # return new value
  __send__(key)
end
Deprecated.


286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/reactor/attributes.rb', line 286

def set_link(key, id_or_path_or_cms_obj)
  target_path = case id_or_path_or_cms_obj
  when Integer then Obj.find(id_or_path_or_cms_obj).path
  when String then id_or_path_or_cms_obj
  when Obj then id_or_path_or_cms_obj.path
  else raise ArgumentError.new("Link target must Integer, String or Obj, but was #{id_or_path_or_cms_obj.class}.")
  end

  edit!
  @force_resolve_refs = true
  crul_obj.set_link(key, target_path.to_s)
end

#suppress_export=(value) ⇒ Object



229
230
231
# File 'lib/reactor/attributes.rb', line 229

def suppress_export=(value)
  set(:suppress_export, value)
end

#title=(value) ⇒ Object



221
222
223
# File 'lib/reactor/attributes.rb', line 221

def title=(value)
  set(:title, value)
end

#title_changed?Boolean

Returns:

  • (Boolean)


241
242
243
# File 'lib/reactor/attributes.rb', line 241

def title_changed?
  attribute_changed?(:title)
end

#upload(data_or_io, extension) ⇒ Object

Note:

Uploaded file is loaded into memory, so try not to do anything silly (like uploading 1GB of data)

Uploads a file/string into a CM. Requires call to save afterwards(!)

Parameters:

  • data_or_io (String, IO)
  • extension (String)

    file extension



276
277
278
279
# File 'lib/reactor/attributes.rb', line 276

def upload(data_or_io, extension)
  self.uploaded = true
  crul_obj.upload(data_or_io, extension)
end

#uploaded?Boolean

Returns:

  • (Boolean)


281
282
283
# File 'lib/reactor/attributes.rb', line 281

def uploaded?
  self.uploaded == true
end

#valid_from=(value) ⇒ Object



185
186
187
# File 'lib/reactor/attributes.rb', line 185

def valid_from=(value)
  set(:valid_from, value)
end

#valid_until=(value) ⇒ Object



189
190
191
# File 'lib/reactor/attributes.rb', line 189

def valid_until=(value)
  set(:valid_until, value)
end