Module: ResqueJobsTree::ResourcesSerializer

Extended by:
ResourcesSerializer
Included in:
ResourcesSerializer
Defined in:
lib/resque_jobs_tree/resources_serializer.rb

Instance Method Summary collapse

Instance Method Details

#argumentize(resources) ⇒ Object

in: [<Localisation id=1>, :pdf] out: [[Localisation, 1], :pdf]



6
7
8
9
10
# File 'lib/resque_jobs_tree/resources_serializer.rb', line 6

def argumentize resources
  resources.to_a.map do |resource|
    resource.respond_to?(:id) ? [resource.class.name, resource.id] : resource
  end
end

#instancize(args) ⇒ Object

in: [[‘Localisation’, 1], :pdf] out: [<Localisation id=1>, :pdf]



14
15
16
17
18
19
20
21
22
# File 'lib/resque_jobs_tree/resources_serializer.rb', line 14

def instancize args
  args.to_a.map do |arg|
    if arg.kind_of? Array
      eval(arg[0]).find(arg[1]) rescue arg
    else
      arg
    end
  end
end