Class: Toy::List

Inherits:
Object show all
Defined in:
lib/toy/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name, *args, &block) ⇒ List

Returns a new instance of List.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/toy/list.rb', line 7

def initialize(model, name, *args, &block)
  @model   = model
  @name    = name.to_sym
  @options = args.extract_options!
  @type    = args.shift

  model.send(list_method)[name] = self

  options[:extensions] = modularized_extensions(block, options[:extensions])

  model.attribute(key, options.fetch(:attribute_type) { Array })
  create_accessors
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



5
6
7
# File 'lib/toy/list.rb', line 5

def model
  @model
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/toy/list.rb', line 5

def name
  @name
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/toy/list.rb', line 5

def options
  @options
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:



41
42
43
44
45
# File 'lib/toy/list.rb', line 41

def eql?(other)
  self.class.eql?(other.class) &&
    model == other.model &&
    name  == other.name
end

#extensionsObject



37
38
39
# File 'lib/toy/list.rb', line 37

def extensions
  options[:extensions]
end

#instance_variableObject



29
30
31
# File 'lib/toy/list.rb', line 29

def instance_variable
  @instance_variable ||= :"@_#{name}"
end

#keyObject



25
26
27
# File 'lib/toy/list.rb', line 25

def key
  @key ||= :"#{name.to_s.singularize}_ids"
end

#new_proxy(owner) ⇒ Object



33
34
35
# File 'lib/toy/list.rb', line 33

def new_proxy(owner)
  proxy_class.new(self, owner)
end

#typeObject



21
22
23
# File 'lib/toy/list.rb', line 21

def type
  @type ||= name.to_s.classify.constantize
end