Class: Mg::Record
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mg::Record
- Defined in:
- lib/mountain-goat/models/mg/record.rb
Instance Method Summary collapse
- #all_metas ⇒ Object
- #meta_for(var) ⇒ Object
-
#set_meta_data(options) ⇒ Object
Set meta data for applicable options-- don't store nil data (waste of space).
Instance Method Details
#all_metas ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mountain-goat/models/mg/record.rb', line 36 def res = {} self..each do |gmt| r = res.count begin if gmt.var =~ /(\w+)[_]id/i if Kernel.const_get($1.classify) item = Kernel.const_get($1.classify).find( self.( gmt.var ) ) if item.respond_to?(:name) res.merge!({ $1 => item.name }) elsif item.respond_to?(:title) res.merge!({ $1 => item.title }) end end end rescue end res.merge!({ gmt.var => self.( gmt.var ) }) if res.count == r end res end |
#meta_for(var) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/mountain-goat/models/mg/record.rb', line 28 def ( var ) gmt = self..find_by_var( var.to_s ) return nil if gmt.nil? m = gmt..find_by_mg_record_id( self.id ) return nil if m.nil? return m.data end |
#set_meta_data(options) ⇒ Object
Set meta data for applicable options-- don't store nil data (waste of space)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mountain-goat/models/mg/record.rb', line 10 def () .each do |option| gmt = self..find_by_var(option[0].to_s) #Create cmt if it doesn't current exist (unless nil) if gmt.nil? && !option[1].nil? && ( option[1].is_a?(Integer) || option[1].is_a?(String) ) #infer type = "gi_meta" if option[1].is_a?(Integer) = "gs_meta" if option[1].is_a?(String) gmt = mg_goal..create!(:name => option[0].to_s, :var => option[0].to_s, :meta_type => ) end if !gmt.nil? #only if we can do it gmt..create!(:mg_record_id => self.id, :data => option[1]) if !option[1].nil? end end end |