Class: Transit::Context
- Inherits:
-
Object
- Object
- Transit::Context
- Includes:
- Mongoid::Document
- Defined in:
- app/models/transit/context.rb
Instance Method Summary collapse
- #ensure_context_position_value ⇒ Object
-
#field_name ⇒ Object
Sets up a default name field to be used in form helpers.
- #file_ext ⇒ Object
- #media_context? ⇒ Boolean
- #package_type ⇒ Object
-
#shortname ⇒ Object
Sets up an “identifier” for the particular context.
- #to_backbone(attrs = {}) ⇒ Object
- #to_js(attrs = {}) ⇒ Object
Instance Method Details
#ensure_context_position_value ⇒ Object
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_name ⇒ Object
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_ext ⇒ Object
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
38 39 40 |
# File 'app/models/transit/context.rb', line 38 def media_context? false end |
#package_type ⇒ Object
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 |
#shortname ⇒ Object
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 |