module Reactor::Attributes::Base
Attributes
uploaded[RW]
Public Class Methods
included(base)
click to toggle source
# File lib/reactor/attributes.rb, line 179 def self.included(base) base.extend(ClassMethods) Reactor::Attributes::LinkListExtender.extend_linklist! end
Public Instance Methods
blob()
click to toggle source
# File lib/reactor/attributes.rb, line 208 def blob if attr_dict.respond_to?(:blob) attr_dict.send :blob else nil end end
blob=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 216 def blob=(value) set(:blob, value) end
body=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 204 def body=(value) set(:body, value) end
body_changed?()
click to toggle source
# File lib/reactor/attributes.rb, line 236 def body_changed? attribute_changed?(:body) end
channels()
click to toggle source
# File lib/reactor/attributes.rb, line 232 def channels self[:channels] || [] end
channels=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 224 def channels=(value) set(:channels, value) end
channels_changed?()
click to toggle source
# File lib/reactor/attributes.rb, line 244 def channels_changed? attribute_changed?(:channels) end
name=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 200 def name=(value) set(:name, value) end
obj_class=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 192 def obj_class=(value) set(:obj_class, value) end
permalink=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 196 def permalink=(value) set(:permalink, value) end
reload_attributes(new_obj_class=nil)
click to toggle source
# File lib/reactor/attributes.rb, line 298 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={})
click to toggle source
Sets given attribute, to given value. Converts values if neccessary @see [Reactor::Attributes] @note options are passed to underlying xml interface, but as of now have no effect
# File lib/reactor/attributes.rb, line 251 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
set_link(key, id_or_path_or_cms_obj)
click to toggle source
@deprecated
# File lib/reactor/attributes.rb, line 285 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)
click to toggle source
# File lib/reactor/attributes.rb, line 228 def suppress_export=(value) set(:suppress_export, value) end
title=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 220 def title=(value) set(:title, value) end
title_changed?()
click to toggle source
# File lib/reactor/attributes.rb, line 240 def title_changed? attribute_changed?(:title) end
upload(data_or_io, extension)
click to toggle source
Uploads a file/string into a CM. Requires call to save afterwards(!) @param [String, IO] data_or_io @param [String] extension file extension @note Uploaded file is loaded into memory, so try not to do anything silly (like uploading 1GB of data)
# File lib/reactor/attributes.rb, line 275 def upload(data_or_io, extension) self.uploaded = true crul_obj.upload(data_or_io, extension) end
uploaded?()
click to toggle source
# File lib/reactor/attributes.rb, line 280 def uploaded? self.uploaded == true end
valid_from=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 184 def valid_from=(value) set(:valid_from, value) end
valid_until=(value)
click to toggle source
# File lib/reactor/attributes.rb, line 188 def valid_until=(value) set(:valid_until, value) end
Protected Instance Methods
__track_dirty_attribute(key)
click to toggle source
# File lib/reactor/attributes.rb, line 395 def __track_dirty_attribute(key) __send__(:attribute_will_change!, key.to_s) end
active_record_attr?(attr)
click to toggle source
# File lib/reactor/attributes.rb, line 310 def active_record_attr?(attr) [:valid_from, :valid_until, :name, :obj_class, :suppress_export, :permalink].include?(attr) end
active_record_set(field, value)
click to toggle source
# File lib/reactor/attributes.rb, line 384 def active_record_set(field, value) @attributes.write_from_user(field.to_s, value) end
allowed_attr?(attr)
click to toggle source
# File lib/reactor/attributes.rb, line 314 def allowed_attr?(attr) return true if builtin_attr?(attr) custom_attrs = self.singleton_class.send(:instance_variable_get, '@_o_allowed_attrs') || self.class.send(:instance_variable_get, '@_o_allowed_attrs') || [] custom_attrs.include?(key_to_attr(attr)) end
builtin_attr?(attr)
click to toggle source
# File lib/reactor/attributes.rb, line 306 def builtin_attr?(attr) [:channels, :parent, :valid_from, :valid_until, :name, :obj_class, :content_type, :body, :blob, :suppress_export, :permalink, :title].include?(attr) end
cached_value?(attr, value)
click to toggle source
# File lib/reactor/attributes.rb, line 379 def cached_value?(attr, value) attribute_type(attr) == :linklist end
crul_set(field, value, options)
click to toggle source
Lazily sets values for crul interface. May be removed in later versions
# File lib/reactor/attributes.rb, line 408 def crul_set(field, value, options) @__crul_attributes ||= {} @__crul_attributes[field.to_sym] = [value, options] end
key_to_attr(key)
click to toggle source
# File lib/reactor/attributes.rb, line 329 def key_to_attr(key) @__attribute_map ||= { :body => :blob, :valid_until => :validUntil, :valid_from => :validFrom, :content_type => :contentType, :suppress_export => :suppressExport, :obj_class => :objClass } key = key.to_sym key = @__attribute_map[key] if @__attribute_map.key?(key) key end
rails_connector_set(field, value, supplied_value)
click to toggle source
# File lib/reactor/attributes.rb, line 357 def rails_connector_set(field, value, supplied_value) field = :blob if field.to_sym == :body field = field.to_sym case attribute_type(field) when :linklist send(:attr_dict).instance_variable_get('@attr_cache')[field] = value send(:attr_dict).send(:blob_dict)[field] = :special_linklist_handling_is_broken when :date if supplied_value.nil? || supplied_value.kind_of?(String) parsed_value = Time.from_iso(value).in_time_zone rescue nil else parsed_value = supplied_value end send(:attr_dict).instance_variable_get('@attr_cache')[field] = parsed_value send(:attr_dict).send(:blob_dict)[field] = value else send(:attr_dict).instance_variable_get('@attr_cache')[field] = nil send(:attr_dict).send(:blob_dict)[field] = value end end
resolve_attribute_alias(key)
click to toggle source
# File lib/reactor/attributes.rb, line 325 def resolve_attribute_alias(key) key end
serialize_value(attr, value)
click to toggle source
# File lib/reactor/attributes.rb, line 344 def serialize_value(attr, value) case attribute_type(attr) when :html HTMLSerializer.new(attr, value).serialize when :date DateSerializer.new(attr, value).serialize when :linklist LinkListSerializer.new(attr, value).serialize else value end end
Private Instance Methods
attribute_type(attr)
click to toggle source
# File lib/reactor/attributes.rb, line 416 def attribute_type(attr) return :html if [:body, :blob].include?(attr.to_sym) return :date if [:valid_from, :valid_until, :last_changed].include?(attr.to_sym) return :string if [:name, :title, :obj_class, :permalink, :suppress_export].include?(attr.to_sym) return :multienum if [:channels].include?(attr.to_sym) custom_attr = self.obj_class_def.try(:custom_attributes).try(:[],attr.to_s) raise TypeError, "obj_class_def is nil for: #{obj_class}" if self.obj_class_def.nil? # FIXME: this should blow up on error # raise TypeError, "Unable to determine type of attribute: #{attr}" if custom_attr.nil? custom_attr ||= {"attribute_type"=>:string} return custom_attr["attribute_type"].to_sym end
path=(*args)
click to toggle source
Calls superclass method
# File lib/reactor/attributes.rb, line 414 def path=(*args) ; super ; end