Class: Item

Inherits:
Object
  • Object
show all
Defined in:
app/models/item.rb

Direct Known Subclasses

Comment

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

Instance Method Summary collapse

Instance Attribute Details

#comments_countObject



32
# File 'app/models/item.rb', line 32

def comments_count; @comments_count ||= 0 end

#layoutObject

Theme layout support



98
99
100
# File 'app/models/item.rb', line 98

def layout
  @layout
end

#nameObject

General Attributes



13
14
15
# File 'app/models/item.rb', line 13

def name
  @name
end

#teaserObject



62
63
64
65
# File 'app/models/item.rb', line 62

def teaser
  generate_teaser! unless @teaser
  @teaser
end

#textObject

General Attributes



13
14
15
# File 'app/models/item.rb', line 13

def text
  @text
end

Instance Method Details

#commentsObject

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 generate_teaser!
  self.teaser = 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 options = {}
  options = options.symbolize_keys
  options[:only] = ((options[:only] || []) + ALLOWED_KEYS).uniq

  # TODO3 files
  # options[:methods] = ((options[:methods] || []) + [:icon_url]).uniq

  super options
end

#to_paramObject

Identity



55
# File 'app/models/item.rb', line 55

def to_param; slug end