Class: Transit::Context

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/transit/context.rb

Direct Known Subclasses

Audio, Text, Video

Instance Method Summary collapse

Instance Method Details

#ensure_context_position_valueObject



15
16
17
18
# File 'app/models/transit/context.rb', line 15

def ensure_context_position_value
  return true unless self.position.nil?
  self.position = _parent.send(:contexts).count + 1
end

#field_nameObject

Sets up a default name field to be used in form helpers



26
27
28
# File 'app/models/transit/context.rb', line 26

def field_name
  (self.name.to_s.blank? ? self.class.to_s : self.name)
end

#file_extObject



30
31
32
# File 'app/models/transit/context.rb', line 30

def file_ext
  File.extname(self.body.to_s).sub('.', '')
end

#media_context?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/transit/context.rb', line 38

def media_context?
  false
end

#package_typeObject



34
35
36
# File 'app/models/transit/context.rb', line 34

def package_type
  (self.package.nil? ? "post" : self.package.class.name.to_s.underscore)
end

#shortnameObject

Sets up an “identifier” for the particular context



21
22
23
# File 'app/models/transit/context.rb', line 21

def shortname
  self.class.to_s.underscore
end

#to_backbone(attrs = {}) ⇒ Object



52
53
54
# File 'app/models/transit/context.rb', line 52

def to_backbone( attrs = {} )
  ::Base64.encode64s(to_js(attrs).to_json)
end

#to_js(attrs = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'app/models/transit/context.rb', line 42

def to_js( attrs = {} )
  { 
    id: self.id.to_s,
    position: self.position.to_i, 
    package_id:   (self.package.nil? ? "" : self.package.id.to_s ),
    package_type: package_type,
    resource_url: package_type.pluralize,
  }.merge!( attrs )
end