Module: Mongoid::Tag::InstanceMethods

Defined in:
lib/mongoid_tag/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_contextObject (readonly)

Returns the value of attribute current_context.



68
69
70
# File 'lib/mongoid_tag/tag.rb', line 68

def current_context
  @current_context
end

#current_meta_modelObject (readonly)

Returns the value of attribute current_meta_model.



68
69
70
# File 'lib/mongoid_tag/tag.rb', line 68

def current_meta_model
  @current_meta_model
end

#meta_model_referancesObject (readonly)

Returns the value of attribute meta_model_referances.



68
69
70
# File 'lib/mongoid_tag/tag.rb', line 68

def meta_model_referances
  @meta_model_referances
end

Instance Method Details

#context_added_tagsObject



112
113
114
# File 'lib/mongoid_tag/tag.rb', line 112

def context_added_tags
  tags_for_context - changes[@current_context.to_s][0].split(",").map(&:strip)
end

#context_has_meta_model?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/mongoid_tag/tag.rb', line 86

def context_has_meta_model?
  !tagify_options[@current_context][:meta_in].blank?
end

#context_is_changed?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/mongoid_tag/tag.rb', line 108

def context_is_changed?
  !changes[@current_context.to_s].blank?
end

#context_meta_modelObject



90
91
92
# File 'lib/mongoid_tag/tag.rb', line 90

def context_meta_model
  send tagify_options[@current_context][:meta_in]
end

#context_removed_tagsObject



116
117
118
# File 'lib/mongoid_tag/tag.rb', line 116

def context_removed_tags
   changes[@current_context.to_s][0].split(",").map(&:strip) - tags_for_context
end

#convert_array_to_string(a) ⇒ Object



74
75
76
# File 'lib/mongoid_tag/tag.rb', line 74

def convert_array_to_string(a)
  a.map(&:strip).join(", ")
end

#convert_string_to_array(s) ⇒ Object



70
71
72
# File 'lib/mongoid_tag/tag.rb', line 70

def convert_string_to_array(s)
  s.split(",").map(&:strip)
end

#decrement_all_in_meta_modelObject



129
130
131
132
133
134
135
136
# File 'lib/mongoid_tag/tag.rb', line 129

def decrement_all_in_meta_model
  tag_contexts.each do |context|
    @current_context = context
    if context_has_meta_model?
      get_meta_model_from_referance(context).update_meta_tags(context, nil, tags_for_context)
    end
  end
end

#get_meta_model_from_referance(context) ⇒ Object



103
104
105
106
# File 'lib/mongoid_tag/tag.rb', line 103

def get_meta_model_from_referance(context)
  referance = @meta_model_referances[context]
  referance[:class].find(referance[:id])
end

#store_referance_to_meta_modelsObject

this is done only to prevent frozen hash error - dont know how to fix it



95
96
97
98
99
100
101
# File 'lib/mongoid_tag/tag.rb', line 95

def store_referance_to_meta_models
  @meta_model_referances = {}
  tag_contexts.each do |context|
    model = send tagify_options[context][:meta_in]
    @meta_model_referances[context] = {:class => model.class, :id => model.id}
  end
end

#tag_contextsObject



78
79
80
# File 'lib/mongoid_tag/tag.rb', line 78

def tag_contexts
  tagify_options.keys
end

#tags_for_contextObject



82
83
84
# File 'lib/mongoid_tag/tag.rb', line 82

def tags_for_context
  send("#{@current_context}_array".to_sym)
end

#update_meta_modelObject



120
121
122
123
124
125
126
127
# File 'lib/mongoid_tag/tag.rb', line 120

def update_meta_model
  tag_contexts.each do |context|
    @current_context = context
    if context_is_changed? && context_has_meta_model?
      context_meta_model.update_meta_tags(context, context_added_tags, context_removed_tags)
    end
  end
end