Module: TentD::Model::TypeProperties

Included in:
NotificationSubscription, Post, PostVersion, ProfileInfo
Defined in:
lib/tentd/model/type_properties.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tentd/model/type_properties.rb', line 4

def self.included(base)
  base.class_eval do
    property :type_base, DataMapper::Property::Text, :required => true, :lazy => false
    property :type_view, String
    property :type_version, String

    validates_with_block :type_version do
      return true if type_base == 'all' || type_version
      [false, 'type version must be set']
    end
  end
end

Instance Method Details

#typeObject



17
18
19
20
21
22
23
# File 'lib/tentd/model/type_properties.rb', line 17

def type
  TentType.new.tap do |t|
    t.base = type_base
    t.version = type_version
    t.view = type_view
  end
end

#type=(new_t) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/tentd/model/type_properties.rb', line 25

def type=(new_t)
  if String === new_t
    new_t = TentType.new(new_t)
  end

  self.type_base = new_t.base
  self.type_version = new_t.version
  self.type_view = new_t.view
end