Module: Writefully::Postable

Extended by:
ActiveSupport::Concern
Included in:
Post
Defined in:
lib/writefully/postable.rb

Defined Under Namespace

Modules: ClassMethods Classes: NoContentField

Instance Method Summary collapse

Instance Method Details

#check_content_field_existenceObject



33
34
35
36
37
# File 'lib/writefully/postable.rb', line 33

def check_content_field_existence
  unless respond_to?(:content)
    raise NoContentField, "No content field defined please define a content field" 
  end
end

#klass_from(type_singular) ⇒ Object



21
22
23
# File 'lib/writefully/postable.rb', line 21

def klass_from type_singular
  type_singular == "tag" ? "Writefully::Tag" : type_singular.classify 
end

#publish_resourceObject



25
26
27
28
29
30
31
# File 'lib/writefully/postable.rb', line 25

def publish_resource
  if publish
    self.published_at = Time.now
  else
    self.published_at = nil
  end
end

#taxonomize_with(tokens, type) ⇒ Object



15
16
17
18
19
# File 'lib/writefully/postable.rb', line 15

def taxonomize_with(tokens, type)
  type_singular = type.to_s.singularize
  type_klass    = klass_from(type_singular).constantize
  self.send(:"#{type_singular}_ids=", type_klass.ids_from_tokens(tokens))
end