Class: Item
- Inherits:
-
Object
- Object
- Item
- Defined in:
- app/models/item.rb
Direct Known Subclasses
Constant Summary collapse
- TEASER_LENGTH =
Teaser
350
- PER_PAGE =
Other
14
- ALLOWED_KEYS =
def inspect
%{#<#{self.class.name} name: "#{name}", #{"slug: #{slug}, " unless slug.blank?}_id: #{_id}>}
end
def to_s
inspect
end
%w{ id _type slug name text tags dependent owner_name viewers created_at updated_at }
Instance Attribute Summary collapse
- #comments_count ⇒ Object
-
#layout ⇒ Object
Theme layout support.
-
#name ⇒ Object
General Attributes.
- #teaser ⇒ Object
-
#text ⇒ Object
General Attributes.
Instance Method Summary collapse
-
#comments ⇒ Object
Aspects.
- #generate_teaser! ⇒ Object
- #to_json(options = {}) ⇒ Object
-
#to_param ⇒ Object
Identity.
Instance Attribute Details
#comments_count ⇒ Object
32 |
# File 'app/models/item.rb', line 32 def comments_count; @comments_count ||= 0 end |
#layout ⇒ Object
Theme layout support
98 99 100 |
# File 'app/models/item.rb', line 98 def layout @layout end |
#name ⇒ Object
General Attributes
13 14 15 |
# File 'app/models/item.rb', line 13 def name @name end |
#teaser ⇒ Object
62 63 64 65 |
# File 'app/models/item.rb', line 62 def unless @teaser @teaser end |
#text ⇒ Object
General Attributes
13 14 15 |
# File 'app/models/item.rb', line 13 def text @text end |
Instance Method Details
#comments ⇒ Object
Aspects
TODO1 add support for security inheritance for comments
26 27 28 |
# File 'app/models/item.rb', line 26 def comments Comment.query({item_id: _id}, {sort: [[:created_at, -1]]}) end |
#generate_teaser! ⇒ Object
68 69 70 |
# File 'app/models/item.rb', line 68 def self. = TextUtils.truncate text, TEASER_LENGTH if text # if new_record? or teaser_changed? end |
#to_json(options = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'app/models/item.rb', line 121 def to_json = {} = .symbolize_keys [:only] = (([:only] || []) + ALLOWED_KEYS).uniq # TODO3 files # options[:methods] = ((options[:methods] || []) + [:icon_url]).uniq super end |
#to_param ⇒ Object
Identity
55 |
# File 'app/models/item.rb', line 55 def to_param; slug end |