Class: Metro::ModelFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/metro/models/model_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ ModelFactory

Returns a new instance of ModelFactory.



6
7
8
9
# File 'lib/metro/models/model_factory.rb', line 6

def initialize(name,options)
  @name = name.to_s.downcase
  @options = options.symbolize_keys
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/metro/models/model_factory.rb', line 4

def name
  @name
end

Instance Method Details

#class_for_actor(model_name) ⇒ Object



28
29
30
# File 'lib/metro/models/model_factory.rb', line 28

def class_for_actor(model_name)
  Models.find(model_name)
end

#createObject



11
12
13
14
# File 'lib/metro/models/model_factory.rb', line 11

def create
  actor_class = class_for_actor(model_name)
  actor_class.new options
end

#load_from_previous_scene?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/metro/models/model_factory.rb', line 16

def load_from_previous_scene?
  @options[:from] == :previous_scene
end

#model_nameObject



24
25
26
# File 'lib/metro/models/model_factory.rb', line 24

def model_name
  options[:model] || name
end

#optionsObject



20
21
22
# File 'lib/metro/models/model_factory.rb', line 20

def options
  @options.except(:from)
end