Module TagsStringsModule::ClassMethods
In: lib/modules/tags_strings_module.rb

Class methods

Methods

Public Instance methods

[Source]

    # File lib/modules/tags_strings_module.rb, line 66
66:     def define_after_initialize(names)
67:       adder = "define_method(:tags_strings_after_initialize) do\n"
68:       names.each do |name|
69:         adder += "if self.\#{name}tags_string\n@\#{name}tags ||= self.\#{name}tags_string.split('/').collect {|s|\nTag.from_s(s)\n}\nelse\n@\#{name}tags ||= []\nend\n"
70:       end
71:       adder += "return true\n" +
72:           "end"
73:       class_eval adder
74:     end

[Source]

    # File lib/modules/tags_strings_module.rb, line 47
47:     def define_attributes(names)
48:       names.each do |name|
49:         # Adds the attribute
50:         class_eval "attr_reader :\#{name}tags\ndef \#{name}tags=(new_tags)\nif new_tags\nnew_tags.uniq!\nif new_tags.size > 7\nself.errors.add :tags, \"are limited to 7 for each logi\"\nend\n@\#{name}tags = new_tags\nend\nend\n"
51:       end
52:     end

[Source]

    # File lib/modules/tags_strings_module.rb, line 85
85:     def define_before_validation(names)
86:       adder = "define_method(:tags_strings_before_validation) do\n"
87:       names.each do |name|
88:         adder += "if @\#{name}tags\nself.\#{name}tags_string = @\#{name}tags.collect {|t|\nt.to_s\n}.join('/')\nelse\nself.\#{name}tags_string = nil\nend\n"
89:       end
90:       adder += "return true\n" +
91:           "end"
92:       class_eval adder
93:     end

Initialization & generation

[Source]

    # File lib/modules/tags_strings_module.rb, line 30
30:     def tags_strings(*tags_names)
31:       names = []
32:       tags_names.each do |t_s|
33:         names << t_s.to_s
34:         if !t_s.nil?
35:           names.last.concat('_')
36:         end
37:       end
38: 
39:       # Attributes
40:       define_attributes(names)
41: 
42:       # Filters
43:       define_after_initialize(names)
44:       define_before_validation(names)
45:     end

[Validate]