infopark_cloud_connector 6.8.0.beta.200.744.99f67fc → 6.8.0.beta.200.785.05d4af9

Sign up to get free protection for your applications and to get access to all the features.
@@ -163,7 +163,7 @@ module RailsConnector
163
163
  end
164
164
 
165
165
  def path_list # :nodoc:
166
- read_attribute(:_path) || []
166
+ read_attribute_value('_path') || []
167
167
  end
168
168
 
169
169
  # returns the Obj's name, i.e. the last component of the path.
@@ -211,7 +211,7 @@ module RailsConnector
211
211
 
212
212
  # returns the obj's permalink.
213
213
  def permalink
214
- read_attribute(:_permalink)
214
+ read_attribute_value('_permalink')
215
215
  end
216
216
 
217
217
  # This method determines the controller that should be invoked when the Obj is requested.
@@ -240,12 +240,12 @@ module RailsConnector
240
240
  end
241
241
 
242
242
  def title
243
- read_attribute(:title)
243
+ read_attribute_value('title')
244
244
  end
245
245
 
246
246
  # Returns the type of the object: :document, :publication, :image or :generic
247
247
  def object_type
248
- read_attribute(:_obj_type).to_sym
248
+ read_attribute_value('_obj_type').to_sym
249
249
  end
250
250
 
251
251
  # Returns true if image? or generic?
@@ -364,31 +364,31 @@ module RailsConnector
364
364
  end
365
365
 
366
366
  def sort_order # :nodoc:
367
- read_attribute(:_sort_order) == 1 ? "descending" : "ascending"
367
+ read_attribute_value('_sort_order') == 1 ? "descending" : "ascending"
368
368
  end
369
369
 
370
370
  def sort_type1 # :nodoc:
371
- converted_sort_type(:_sort_type1)
371
+ converted_sort_type('_sort_type1')
372
372
  end
373
373
 
374
374
  def sort_type2 # :nodoc:
375
- converted_sort_type(:_sort_type2)
375
+ converted_sort_type('_sort_type2')
376
376
  end
377
377
 
378
378
  def sort_type3 # :nodoc:
379
- converted_sort_type(:_sort_type3)
379
+ converted_sort_type('_sort_type3')
380
380
  end
381
381
 
382
382
  def sort_key1 # :nodoc:
383
- converted_sort_key(:_sort_key1)
383
+ converted_sort_key('_sort_key1')
384
384
  end
385
385
 
386
386
  def sort_key2 # :nodoc:
387
- converted_sort_key(:_sort_key2)
387
+ converted_sort_key('_sort_key2')
388
388
  end
389
389
 
390
390
  def sort_key3 # :nodoc:
391
- converted_sort_key(:_sort_key3)
391
+ converted_sort_key('_sort_key3')
392
392
  end
393
393
 
394
394
  # Returns the Object with the given name next in the hierarchy
@@ -399,13 +399,15 @@ module RailsConnector
399
399
  parent.find_nearest(name) unless self.root?
400
400
  end
401
401
 
402
- OLD_INTERNAL_KEYS = Set.new(%w(
402
+ # This should be a SET, because it's faster in this particular case.
403
+ OLD_INTERNAL_KEYS = Set.new(%w[
403
404
  body
404
405
  id
405
406
  last_changed
406
407
  name
407
408
  obj_class
408
409
  obj_type
410
+ object_type
409
411
  path
410
412
  permalink
411
413
  sort_key1
@@ -417,20 +419,24 @@ module RailsConnector
417
419
  sort_type3
418
420
  suppress_export
419
421
  text_links
422
+ title
420
423
  valid_from
421
424
  valid_until
422
- ))
423
- # Returns the value of the attribute specified by its name.
424
- #
425
+ ])
426
+
427
+ # Returns the value of an internal or external attribute specified by its name.
425
428
  # Passing an invalid key will not raise an error, but return nil.
426
- def [](raw_key)
427
- key = raw_key.to_s
429
+ def [](key)
430
+ key = key.to_s
428
431
  if OLD_INTERNAL_KEYS.include?(key)
429
432
  send(key)
430
- elsif key.start_with?('_')
431
- send(key.slice(1..-1))
432
- else
433
+ elsif key.start_with?('_') && OLD_INTERNAL_KEYS.include?(internal_key = key[1..-1])
434
+ # For backwards compatibility reasons
435
+ send(internal_key)
436
+ elsif has_attribute?(key)
433
437
  read_attribute(key)
438
+ else
439
+ nil
434
440
  end
435
441
  end
436
442
 
@@ -443,23 +449,23 @@ module RailsConnector
443
449
  end
444
450
 
445
451
  def text_links
446
- read_attribute(:_text_links)
452
+ read_attribute_value('_text_links')
447
453
  end
448
454
 
449
455
  def obj_class
450
- read_attribute(:_obj_class)
456
+ read_attribute_value('_obj_class')
451
457
  end
452
458
 
453
459
  def last_changed
454
- read_attribute(:_last_changed)
460
+ read_attribute_value('_last_changed')
455
461
  end
456
462
 
457
463
  def valid_from
458
- read_attribute(:_valid_from)
464
+ read_attribute_value('_valid_from')
459
465
  end
460
466
 
461
467
  def valid_until
462
- read_attribute(:_valid_until)
468
+ read_attribute_value('_valid_until')
463
469
  end
464
470
 
465
471
  # For a binary Obj, the content_type is equal to the content_type of it's body (i.e. it's data).
@@ -497,12 +503,7 @@ module RailsConnector
497
503
  # Returns a list of the names of all custom attributes defined for this Obj as Symbols.
498
504
  # A custom attribute is a user-defined attribute, i.e. one that is not built-in in the CMS.
499
505
  def custom_attribute_names
500
- attributes.keys.map(&:to_sym)
501
- end
502
-
503
- def has_attribute?(name)
504
- name_as_string = name.to_s
505
- @values.has_key?(name_as_string) || attributes.has_key?(name_as_string)
506
+ obj_class_instance.attributes.map(&:to_sym)
506
507
  end
507
508
 
508
509
  def self.preview_time=(t) # :nodoc:
@@ -517,52 +518,85 @@ module RailsConnector
517
518
  "<#{self.class} id=\"#{id}\" path=\"#{path}\">"
518
519
  end
519
520
 
521
+ def has_attribute?(name)
522
+ obj_class_instance.has_attribute?(name)
523
+ end
524
+
520
525
  private
521
526
 
527
+ def obj_class_instance
528
+ ObjClass.by_name(obj_class)
529
+ end
530
+
522
531
  def update_data(values = {}, meta = {})
523
532
  @values = values || {}
524
533
  meta ||= {}
525
- @rtc_ref = meta["rtc_ref"]
526
- @ext_ref = meta["ext_ref"]
527
- @attr_cache = {}
534
+ @rtc_ref = meta['rtc_ref']
535
+ @ext_ref = meta['ext_ref']
536
+ @attribute_cache = {}
528
537
  end
529
538
 
530
- def attributes
531
- @attributes ||= @rtc_ref ? (
532
- rtc = DictStorage.get(@rtc_ref)
533
- if rtc['obj_classes'] && rtc['attributes'] && oc = rtc['obj_classes'][@values['_obj_class']]
534
- rtc['attributes'].inject({}) do |attrs, (name, value)|
535
- attrs[name] = value if oc['attributes'] && oc['attributes'].include?(name)
536
- attrs
537
- end
538
- else
539
- {}
540
- end
541
- ) : {}
539
+ def read_attribute(attribute_name)
540
+ attribute_type = Attribute.type_of(attribute_name)
541
+ if type_of(attribute_name) == attribute_type
542
+ read_attribute_value(attribute_name, attribute_type)
543
+ else
544
+ default_attribute_value(attribute_type)
545
+ end
542
546
  end
543
547
 
544
- def read_attribute(name)
545
- name = name.to_s
546
- @attr_cache[name] ||= attribute_value_from_raw_attribute_value(name)
548
+ def read_attribute_value(attribute_name, attribute_type = nil)
549
+ @attribute_cache.fetch(attribute_name) do
550
+ attribute_type ||= type_of(attribute_name)
551
+ attribute_value = read_raw_attribute_value(attribute_name)
552
+ @attribute_cache[attribute_name] =
553
+ prepare_attribute_value(attribute_name, attribute_type, attribute_value)
554
+ end
547
555
  end
548
556
 
549
- def attribute_value_from_raw_attribute_value(name)
550
- raw = read_raw_attribute_value(name)
551
- case type_of(name)
557
+ def prepare_attribute_value(attribute_name, attribute_type, attribute_value)
558
+ case attribute_type
552
559
  when :markdown
553
- StringTagging.tag_as_markdown(raw, self)
560
+ StringTagging.tag_as_markdown(attribute_value, self)
554
561
  when :html
555
- StringTagging.tag_as_html(raw, self)
562
+ StringTagging.tag_as_html(attribute_value, self)
556
563
  when :date
557
- DateAttribute.parse raw if raw
564
+ DateAttribute.parse(attribute_value) if attribute_value
558
565
  when :linklist
559
- if name == "_text_links"
560
- LinkList.new(raw && raw.values)
566
+ if attribute_name == '_text_links'
567
+ LinkList.new(attribute_value && attribute_value.values)
561
568
  else
562
- LinkList.new(raw)
569
+ LinkList.new(attribute_value)
570
+ end
571
+ else
572
+ attribute_value
573
+ end
574
+ end
575
+
576
+ def default_attribute_value(attribute_type)
577
+ case attribute_type
578
+ when :linklist
579
+ LinkList.new(nil)
580
+ when :multienum
581
+ []
582
+ else
583
+ nil
584
+ end
585
+ end
586
+
587
+ def attributes
588
+ @attributes ||= @rtc_ref ? attributes_from_rtc : {}
589
+ end
590
+
591
+ def attributes_from_rtc
592
+ rtc = DictStorage.get(@rtc_ref)
593
+ if rtc['obj_classes'] && rtc['attributes'] && oc = rtc['obj_classes'][@values['_obj_class']]
594
+ rtc['attributes'].inject({}) do |attrs, (name, value)|
595
+ attrs[name] = value if oc['attributes'] && oc['attributes'].include?(name)
596
+ attrs
563
597
  end
564
598
  else
565
- raw
599
+ {}
566
600
  end
567
601
  end
568
602
 
@@ -591,9 +625,9 @@ module RailsConnector
591
625
  DateAttribute.parse(value) unless value.nil?
592
626
  end
593
627
 
594
- def method_missing(method_id, *args) # :nodoc:
595
- if has_attribute?(method_id)
596
- read_attribute(method_id)
628
+ def method_missing(method_name, *args) # :nodoc:
629
+ if has_attribute?(method_name)
630
+ read_attribute(method_name.to_s)
597
631
  else
598
632
  super
599
633
  end
@@ -620,11 +654,11 @@ module RailsConnector
620
654
  end
621
655
 
622
656
  def converted_sort_type(attribute)
623
- read_attribute(attribute) == 1 ? "numeric" : "alphaNumeric"
657
+ read_attribute_value(attribute) == 1 ? "numeric" : "alphaNumeric"
624
658
  end
625
659
 
626
660
  def converted_sort_key(attribute)
627
- key = read_attribute(attribute)
661
+ key = read_attribute_value(attribute)
628
662
  case key
629
663
  when "_valid_until"
630
664
  "_valid_until"
@@ -7,7 +7,7 @@ module ObjBody
7
7
  if binary?
8
8
  nil
9
9
  else
10
- StringTagging.tag_as_html(read_attribute(:body), self)
10
+ StringTagging.tag_as_html(read_attribute_value('body'), self)
11
11
  end
12
12
  end
13
13
 
@@ -52,7 +52,7 @@ module ObjBody
52
52
  private
53
53
 
54
54
  def find_blob
55
- blob_spec = read_attribute(:blob)
55
+ blob_spec = read_attribute_value('blob')
56
56
  Blob.find(blob_spec["id"], :context => path) if blob_spec
57
57
  end
58
58
  end
@@ -1,15 +1,18 @@
1
1
  #:enddoc:
2
2
  module RailsConnector
3
3
  class ObjClass
4
- attr_reader :name
4
+ attr_reader :name, :attributes
5
5
 
6
6
  def initialize(data)
7
- @name, @attributes = data['name'], data['attributes']
7
+ @name, @attributes = data['name'], data['attributes'] || []
8
8
  end
9
9
 
10
10
  def self.by_name(name)
11
- data = Revision.current.obj_classes[name.to_s]
12
- new(data) if data
11
+ if data = Revision.current.obj_classes[name.to_s]
12
+ new(data)
13
+ else
14
+ raise ResourceNotFound, "Could not find #{self} with name #{name}"
15
+ end
13
16
  end
14
17
 
15
18
  def has_attribute?(attribute_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: -71426954407
4
+ hash: 77657614921
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 6
@@ -9,12 +9,13 @@ version: !ruby/object:Gem::Version
9
9
  - 0
10
10
  - beta
11
11
  - 200
12
- - 744
13
- - 99
14
- - f
15
- - 67
16
- - fc
17
- version: 6.8.0.beta.200.744.99f67fc
12
+ - 785
13
+ - 5
14
+ - d
15
+ - 4
16
+ - af
17
+ - 9
18
+ version: 6.8.0.beta.200.785.05d4af9
18
19
  platform: ruby
19
20
  authors:
20
21
  - Infopark AG
@@ -22,7 +23,7 @@ autorequire:
22
23
  bindir: bin
23
24
  cert_chain: []
24
25
 
25
- date: 2012-07-05 00:00:00 +02:00
26
+ date: 2012-07-18 00:00:00 +02:00
26
27
  default_executable:
27
28
  dependencies:
28
29
  - !ruby/object:Gem::Dependency
@@ -63,19 +64,20 @@ dependencies:
63
64
  requirements:
64
65
  - - "="
65
66
  - !ruby/object:Gem::Version
66
- hash: -71426954407
67
+ hash: 77657614921
67
68
  segments:
68
69
  - 6
69
70
  - 8
70
71
  - 0
71
72
  - beta
72
73
  - 200
73
- - 744
74
- - 99
75
- - f
76
- - 67
77
- - fc
78
- version: 6.8.0.beta.200.744.99f67fc
74
+ - 785
75
+ - 5
76
+ - d
77
+ - 4
78
+ - af
79
+ - 9
80
+ version: 6.8.0.beta.200.785.05d4af9
79
81
  version_requirements: *id003
80
82
  name: kvom
81
83
  prerelease: false