Class: ResourceCode

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/resource_code.rb

Class Method Summary collapse

Class Method Details

.find_by_liferay_class(args = {}) ⇒ Object

ResourceCode associated to an Liferay class

Args:

- :companyid
- :name
- :scope (defaults to 4)


19
20
21
22
23
# File 'lib/resource_code.rb', line 19

def self.find_by_liferay_class(args={})
  args.update(:scope => 4) unless args[:scope]
  ResourceCode.get(:first,
    :conditions => "companyid=#{args[:companyid]} AND name='#{args[:name]}' AND scope=#{args[:scope]}")
end

.get(args) ⇒ Object

Finds existing or creates a new ResourceCode Args:

- :companyid
- :name
- :scope


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/resource_code.rb', line 30

def self.get(args)
  conditions = []
  args.each_pair{ |k,v|
    conditions << (k==:name ?
      ("%s='%s'" % [k,v]) : ("%s=%s" % [k,v]))
  }
  #logger.debug conditions.inspect
  rc = ResourceCode.find(:first, :conditions => conditions.join(' AND '))
  unless rc
    logger.debug 'creating new ResourceCode'
    rc = self.create(args)
  end
  return rc
end