class Smith::Commands::Acl
Public Instance Methods
_acl()
click to toggle source
# File lib/smith/commands/smithctl/acl.rb, line 11 def _acl acl_type_cache = AclTypeCache.instance if options[:show] if target.empty? "You must supply an ACL file name." else target.map do |acl| if options[:source_given] acls = find_acl(Smith.acl_cache_directory, acl, 'pb.rb') else acls = find_acl(Smith.acl_directories, acl, 'proto') end case acls.length when 0 "ACL file does not exist." when 1 if target.length == 1 "\n#{indent_acl(acls.first.read)}\n" else "\n#{acl} ->\n#{indent_acl(acls.first.read)}" end else "There are multiple ACLs with the name: #{target}" end end.join("\n") end elsif options[:clean_given] Pathname.glob(Smith.acl_cache_directory.join("*.pb.rb")).each {|p| p.unlink} "" elsif options[:compile_given] Pathname.glob(Smith.compile_acls) "" else join_string = (options[:long]) ? "\n" : " " acl_type_cache.dump_types.keys.map(&:to_s).sort.join(join_string) # Pathname.glob(Smith.acl_directories.map {|p| "#{p}#{File::SEPARATOR}*"}).map do |p| # p.basename(".proto") # end.sort.join(join_string) end end
execute()
click to toggle source
# File lib/smith/commands/smithctl/acl.rb, line 7 def execute responder.succeed(_acl) end
Private Instance Methods
find_acl(directories, acl, ext)
click to toggle source
# File lib/smith/commands/smithctl/acl.rb, line 56 def find_acl(directories, acl, ext) [directories].flatten.inject([]) do |a, directory| a.tap do |acc| acl_file = directory.join("#{acl.snake_case}.#{ext}") acc << acl_file if acl_file.exist? end end end
indent_acl(acl)
click to toggle source
# File lib/smith/commands/smithctl/acl.rb, line 65 def indent_acl(acl) acl.split("\n").map { |l| l.sub(/^/, " ") }.join("\n") end
options_spec()
click to toggle source
# File lib/smith/commands/smithctl/acl.rb, line 69 def options_spec banner "List and display acl files.", "[acl]" opt :long, "format the listing", :short => :l opt :show, "show the contents of the acl file", :short => :s opt :source, "show the contents of the generated acl file", :depends => :show opt :clean, "remove all compiled acls", :short => :none opt :compile, "compile all acls", :short => :none end