class ChefFixie::Sql::Org

Constants

NAME_FIXUP

Iterators for objects in authz; using containers to enumerate things It might be better to metaprogram this up instead,

TODO Write some tests to validate that this stuff works, since it depends on a lot of name magic…

Public Class Methods

new(data) click to toggle source
Calls superclass method ChefFixie::Sql::SqlObject::new
# File lib/chef_fixie_shahid/sql_objects.rb, line 144
def initialize(data)
  super(data)
end
scoped_type(*args) click to toggle source
# File lib/chef_fixie_shahid/sql_objects.rb, line 135
def self.scoped_type(*args)
  args.each do |object|
    funname = Relationships.plural(object)
    # defer evaluation of mapper to make sure we have a chance for everyone to initialize
    fundef = "def #{funname}; Relationships.table_class(:#{object}).new.by_org_id(org_id); end"
    class_eval(fundef)
  end
end

Public Instance Methods

each_authz_object() { |object| ... } click to toggle source
# File lib/chef_fixie_shahid/sql_objects.rb, line 189
def each_authz_object
  each_authz_object_by_class do |objectlist|
    objectlist.each do |object|
      yield object
    end
  end
  nil
end
each_authz_object_by_class() { |objects| ... } click to toggle source
# File lib/chef_fixie_shahid/sql_objects.rb, line 178
def each_authz_object_by_class
  containers = self.containers.all(:all)
  containers.each do |container|
    objects = objects_by_container_type(container.name)
    if block_given?
      yield objects
    end
  end
  nil
end
global_admins() click to toggle source
# File lib/chef_fixie_shahid/sql_objects.rb, line 152
def global_admins
  name = self.name
  global_admins_name = "#{name}_global_admins"
  read_access_name = "#{name}_read_access_group"
  ChefFixie::Sql::Groups.new[global_admins_name] || \
    ChefFixie::Sql::Groups.new[read_access_name]
end
Also aliased as: read_access_group
objects_by_container_type(container) click to toggle source
# File lib/chef_fixie_shahid/sql_objects.rb, line 169
def objects_by_container_type(container)
  name = NAME_FIXUP.has_key?(container) ? NAME_FIXUP[container] : container
  return [] if name.nil?

  object_type = name.to_sym
  #        raise Exception "No such object_type #{object_type}" unless respond_to?(object_type)
  send(object_type).all(:all)
end
org_id() click to toggle source
# File lib/chef_fixie_shahid/sql_objects.rb, line 148
def org_id
  data[:id]
end
read_access_group()
Alias for: global_admins