module Writefully::Postable::ClassMethods

Public Instance Methods

by_taxonomies(taxonomies, type) click to toggle source
# File lib/writefully/postable.rb, line 64
def by_taxonomies(taxonomies, type)
  joins(type.to_sym)
  .where(writefully_tags: { slug: taxonomies, 
                            type: (type == "tags" ? nil : type.classify) })
  .uniq
end
filter_with(filters) click to toggle source
# File lib/writefully/postable.rb, line 56
def filter_with(filters)
  if filters.present?
    filters.keys.inject(self) do |klass, type| 
      klass.where(id: by_taxonomies(filters[type].split(/,/), type))
    end
  else all end
end
wf_content(field_name) click to toggle source
# File lib/writefully/postable.rb, line 71
def wf_content(field_name)
  class_eval do 
    alias_attribute :content, :"#{field_name}" unless field_name == :content
  end
end
wf_taxonomize(type, *args) click to toggle source
# File lib/writefully/postable.rb, line 42
def wf_taxonomize(type, *args)
  class_eval do 
    has_many :"#{type}", *args

    define_method("all_#{type}") do 
      read_attribute(:"all_#{type}").map { |taxon| Hashie::Mash.new(taxon) }
    end

    define_method("#{type}=") do |tokens|
      self.taxonomize_with(tokens, type)
    end
  end
end