Class: Mongoid::TagsArentHard::Tags

Inherits:
BasicObject
Extended by:
Origin::Extensions::Array::ClassMethods
Defined in:
lib/mongoid/tags_arent_hard/tags.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*tag_list, options) ⇒ Tags

delegate :join, :map, :each, :inspect, :==, :===, :eql?, :bson_dump, :delete, :&, :to_ary, :to_json, :as_json, to: :tag_list



10
11
12
13
14
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 10

def initialize(*tag_list, options)
  self.options = {separator: ::Mongoid::TagsArentHard.config.separator}.merge(options)
  self.tag_list = []
  self.<<(*tag_list)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



43
44
45
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 43

def method_missing(sym, *args, &block)
  self.tag_list.send(sym, *args, &block)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 7

def options
  @options
end

#tag_listObject

Returns the value of attribute tag_list.



6
7
8
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 6

def tag_list
  @tag_list
end

Class Method Details

.demongoize(object) ⇒ Object



71
72
73
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 71

def self.demongoize(object)
  object
end

.mongoize(object) ⇒ Object



67
68
69
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 67

def self.mongoize(object)
  evolve(object)
end

Instance Method Details

#!=(other) ⇒ Object



63
64
65
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 63

def !=(other)
  !self.==(other)
end

#+(*tag_list) ⇒ Object



31
32
33
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 31

def +(*tag_list)
  self.<<(*tag_list)
end

#<<(*tag_list) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 21

def <<(*tag_list)
  self.tag_list << self.normalize(*tag_list)
  self.tag_list.flatten!
  self.tag_list.uniq!
  if self.options[:owner]
    self.options[:owner].send("#{self.options[:_name]}_will_change!")
  end
  return self
end

#==(other) ⇒ Object



59
60
61
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 59

def ==(other)
  self.tag_list == other
end

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 55

def is_a?(klass)
  self.kind_of?(klass)
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 51

def kind_of?(klass)
  klass == ::Mongoid::TagsArentHard::Tags || klass == ::Array
end

#normalize(*tag_list) ⇒ Object



16
17
18
19
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 16

def normalize(*tag_list)
  x = tag_list.flatten.compact.map {|s| s.split(self.options[:separator]).map {|x| x.strip}}.flatten
  return x
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 47

def respond_to_missing?(method_name, include_private = false)
  self.tag_list.respond_to?(method_name)
end

#to_sObject



35
36
37
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 35

def to_s
  self.join(self.options[:separator])
end

#to_strObject



39
40
41
# File 'lib/mongoid/tags_arent_hard/tags.rb', line 39

def to_str
  self.to_s
end