Module: Mongoid::Tag::InstanceMethods
- Defined in:
- lib/mongoid_tag/tag.rb
Instance Attribute Summary collapse
-
#current_context ⇒ Object
readonly
Returns the value of attribute current_context.
-
#current_meta_model ⇒ Object
readonly
Returns the value of attribute current_meta_model.
-
#meta_model_referances ⇒ Object
readonly
Returns the value of attribute meta_model_referances.
Instance Method Summary collapse
- #context_added_tags ⇒ Object
- #context_has_meta_model? ⇒ Boolean
- #context_is_changed? ⇒ Boolean
- #context_meta_model ⇒ Object
- #context_removed_tags ⇒ Object
- #convert_array_to_string(a) ⇒ Object
- #convert_string_to_array(s) ⇒ Object
- #decrement_all_in_meta_model ⇒ Object
- #get_meta_model_from_referance(context) ⇒ Object
-
#store_referance_to_meta_models ⇒ Object
this is done only to prevent frozen hash error - dont know how to fix it.
- #tag_contexts ⇒ Object
- #tags_for_context ⇒ Object
- #update_meta_model ⇒ Object
Instance Attribute Details
#current_context ⇒ Object (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_model ⇒ Object (readonly)
Returns the value of attribute current_meta_model.
68 69 70 |
# File 'lib/mongoid_tag/tag.rb', line 68 def @current_meta_model end |
#meta_model_referances ⇒ Object (readonly)
Returns the value of attribute meta_model_referances.
68 69 70 |
# File 'lib/mongoid_tag/tag.rb', line 68 def @meta_model_referances end |
Instance Method Details
#context_added_tags ⇒ Object
112 113 114 |
# File 'lib/mongoid_tag/tag.rb', line 112 def - changes[@current_context.to_s][0].split(",").map(&:strip) end |
#context_has_meta_model? ⇒ Boolean
86 87 88 |
# File 'lib/mongoid_tag/tag.rb', line 86 def ![@current_context][:meta_in].blank? end |
#context_is_changed? ⇒ 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_model ⇒ Object
90 91 92 |
# File 'lib/mongoid_tag/tag.rb', line 90 def send [@current_context][:meta_in] end |
#context_removed_tags ⇒ Object
116 117 118 |
# File 'lib/mongoid_tag/tag.rb', line 116 def changes[@current_context.to_s][0].split(",").map(&:strip) - 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_model ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/mongoid_tag/tag.rb', line 129 def tag_contexts.each do |context| @current_context = context if (context).(context, nil, ) end end end |
#get_meta_model_from_referance(context) ⇒ Object
103 104 105 106 |
# File 'lib/mongoid_tag/tag.rb', line 103 def (context) referance = @meta_model_referances[context] referance[:class].find(referance[:id]) end |
#store_referance_to_meta_models ⇒ Object
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 @meta_model_referances = {} tag_contexts.each do |context| model = send [context][:meta_in] @meta_model_referances[context] = {:class => model.class, :id => model.id} end end |
#tag_contexts ⇒ Object
78 79 80 |
# File 'lib/mongoid_tag/tag.rb', line 78 def tag_contexts .keys end |
#tags_for_context ⇒ Object
82 83 84 |
# File 'lib/mongoid_tag/tag.rb', line 82 def send("#{@current_context}_array".to_sym) end |
#update_meta_model ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/mongoid_tag/tag.rb', line 120 def tag_contexts.each do |context| @current_context = context if context_is_changed? && .(context, , ) end end end |