Module: Authorize::Graph::Fixtures

Defined in:
lib/authorize/graph/fixtures.rb

Class Method Summary collapse

Class Method Details

.create_fixtures(db = Redis::Base.db, pathname = Pathname.new(ActiveSupport::TestCase.fixture_path).join('authorize', 'role_graph.yml'), flush = true) ⇒ Object



11
12
13
14
# File 'lib/authorize/graph/fixtures.rb', line 11

def create_fixtures(db = Redis::Base.db, pathname = Pathname.new(ActiveSupport::TestCase.fixture_path).join('authorize', 'role_graph.yml'), flush = true)
  db.flushdb if flush
  YAML.load(ERB.new(pathname.read).result)
end

.name_to_key(name) ⇒ Object



28
29
30
# File 'lib/authorize/graph/fixtures.rb', line 28

def self.name_to_key(name)
  ::Fixtures.identify(name).to_s
end

.process(graph, nodes, parent = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/authorize/graph/fixtures.rb', line 17

def self.process(graph, nodes, parent = nil)
  nodes.each do |node|
    name = node.respond_to?(:keys) ? node.keys.first : node
    children = node.respond_to?(:values) ? node.values.first : []
    key = name_to_key(name)
    vertex = graph.vertex(key)
    graph.edge(nil, parent, vertex) if parent
    process(graph, children, vertex) unless children.empty?
  end
end