Module: ActsAsWordCloud::WordCloud::ClassMethods

Defined in:
lib/acts_as_word_cloud/word_cloud.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_word_cloud(args = {}) ⇒ Object

Sets up the word_cloud method and takes arguments that control what it returns

Parameters:

  • args (Hash) (defaults to: {})
  • args (Array) (defaults to: {})

    :included_methods An array of method symbols used to create this model’s word cloud

  • args (Array) (defaults to: {})

    :excluded_methods An array of method symbols used to remove data from the word cloud. This should be used to remove database fields from the word cloud.

  • args (Array) (defaults to: {})

    :excluded_models An array of models whose data should not be included in the word cloud

  • args (Integer) (defaults to: {})

    :depth_level How many levels of associations to include

  • args (Symbol) (defaults to: {})

    :object_name_method How to name the object when included in the word cloud as an association



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acts_as_word_cloud/word_cloud.rb', line 16

def acts_as_word_cloud(args = {})

  # getter/setter methods for the module
  mattr_accessor :word_cloud_attributes unless respond_to? :word_cloud_attributes
  allowed_options = [:included_methods, :excluded_methods, :excluded_models, :depth, :object_name_methods]

  # set defaults
  args[:included_methods] ||= []
  args[:excluded_methods] ||= []

  args[:excluded_models] ||= []
  args[:excluded_models] |= ::ActsAsWordCloud.config.permanently_excluded_models

  args[:depth] ||= ::ActsAsWordCloud.config.default_search_depth
  # note that the user passes in object_name_method and it is turned into the array object_name_methods
  args[:object_name_methods] = args[:object_name_method] ? [args[:object_name_method]] : ::ActsAsWordCloud.config.object_name_methods

  self.word_cloud_attributes = args.keep_if { |key| allowed_options.include?(key) }

  include ActsAsWordCloud::WordCloud::InstanceMethods
end