Module: Reactor::Attributes::Base

Defined in:
lib/reactor/attributes.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



21
22
23
24
# File 'lib/reactor/attributes.rb', line 21

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

Instance Method Details

#_read_attribute(key) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/reactor/attributes.rb', line 74

def _read_attribute(key)
  if active_record_attr?(key)
    super
  else
    __send__(key)
  end
end

#blobObject



50
51
52
# File 'lib/reactor/attributes.rb', line 50

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

#blob=(value) ⇒ Object



54
55
56
# File 'lib/reactor/attributes.rb', line 54

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

#body=(value) ⇒ Object



46
47
48
# File 'lib/reactor/attributes.rb', line 46

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

#channelsObject



66
67
68
# File 'lib/reactor/attributes.rb', line 66

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

#channels=(value) ⇒ Object



62
63
64
# File 'lib/reactor/attributes.rb', line 62

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

#name=(value) ⇒ Object



42
43
44
# File 'lib/reactor/attributes.rb', line 42

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

#obj_class=(value) ⇒ Object



34
35
36
# File 'lib/reactor/attributes.rb', line 34

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

#permalink=(value) ⇒ Object



38
39
40
# File 'lib/reactor/attributes.rb', line 38

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

#reload_attributes(new_obj_class = nil) ⇒ Object



133
134
135
136
137
138
# File 'lib/reactor/attributes.rb', line 133

def reload_attributes(new_obj_class = nil)
  new_obj_class ||= obj_class
  RailsConnector::Meta::EagerLoader.instance.forget_obj_class(new_obj_class)
  Reactor::AttributeHandlers.reinstall_attributes(singleton_class, new_obj_class)
  self.class.reinitialize_attributes
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]


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/reactor/attributes.rb', line 85

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

  attribute_will_change!(key.to_s)

  attribute = key_to_attr(key)

  formated_value = serialize_value(key, value)
  crul_set(attribute, formated_value, options)

  if active_record_attr?(key)
    formated_value = to_time_in_zone(formated_value) if attribute_type(key) == :date
  else
    rails_connector_set(key, formated_value)
  end
  @attributes.write_from_user(key.to_s, formated_value)
  __send__(key)
end
Deprecated.


120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/reactor/attributes.rb', line 120

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, "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



70
71
72
# File 'lib/reactor/attributes.rb', line 70

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

#title=(value) ⇒ Object



58
59
60
# File 'lib/reactor/attributes.rb', line 58

def title=(value)
  set(:title, value)
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



110
111
112
113
# File 'lib/reactor/attributes.rb', line 110

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

#uploaded?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/reactor/attributes.rb', line 115

def uploaded?
  uploaded == true
end

#valid_from=(value) ⇒ Object



26
27
28
# File 'lib/reactor/attributes.rb', line 26

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

#valid_until=(value) ⇒ Object



30
31
32
# File 'lib/reactor/attributes.rb', line 30

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