app/controllers/configurations/book_controller.rb
def reference_book_configurations()
    return Rails.cache.fetch("odsa_reference_book_configs", expires_in: 6.hours) do
             config_dir = File.join("public", "OpenDSA", "config")
             base_url = request.protocol + request.host_with_port + "/OpenDSA/config/"
             configs = []
             Dir.foreach(config_dir) do |entry|
               if entry.include?("_generated.json") or not File.extname(entry) == '.json'
                 next
               end
               url = base_url + File.basename(entry)
               begin
                 title = JSON.parse(File.read(File.join(config_dir, entry)))["title"]
                 configs << {
                   title: title,
                   name: File.basename(entry, '.json'),
                   url: url,
                 }
               rescue
                 error = Error.new(:class_name => 'book_config_parse_fail',
                                   :message => "Failed to parse #{entry}")
                 error.save!
               end
             end
             configs.sort_by! { |x| x[:title] }
           end
  end
# Gets a list of book configurations hosted on the OpenDSA server
# Returns a dictionary containing the name, title, and url of each config file
Gets a list of book configurations hosted on the OpenDSA server
Returns a dictionary containing the name, title, and url of each config file
Gets a list of book configurations hosted on the OpenDSA server Returns a dictionary containing the name title and url of each config file
def reference_book_configurations()
    return Rails.cache.fetch("odsa_reference_book_configs", expires_in: 6.hours) do
             config_dir = File.join("public", "OpenDSA", "config")
             base_url = request.protocol + request.host_with_port + "/OpenDSA/config/"
             configs = []
             Dir.foreach(config_dir) do |entry|
               if entry.include?("_generated.json") or not File.extname(entry) == '.json'
                 next
               end
               url = base_url + File.basename(entry)
               begin
                 title = JSON.parse(File.read(File.join(config_dir, entry)))["title"]
                 configs << {
                   title: title,
                   name: File.basename(entry, '.json'),
                   url: url,
                 }
               rescue
                 error = Error.new(:class_name => 'book_config_parse_fail',
                                   :message => "Failed to parse #{entry}")
                 error.save!
               end
             end
             configs.sort_by! { |x| x[:title] }
           end
  end
def reference_book_configurations ( ) return Rails . cache . fetch ( "odsa_reference_book_configs" , expires_in : 6 . hours ) do config_dir = File . join ( "public" , "OpenDSA" , "config" ) base_url = request . protocol + request . host_with_port + "/OpenDSA/config/" configs = [ ] Dir . foreach ( config_dir ) do | entry | if entry . include? ( "_generated.json" ) or not File . extname ( entry ) == '.json' next end url = base_url + File . basename ( entry ) begin title = JSON . parse ( File . read ( File . join ( config_dir , entry ) ) ) [ "title" ] configs << { title : title , name : File . basename ( entry , '.json' ) , url : url , } rescue error = Error . new ( :class_name => 'book_config_parse_fail' , :message => "Failed to parse #{entry}" ) error . save! end end configs . sort_by! { | x | x [ :title ] } end end
Gets a list of book configurations hosted on the OpenDSA server
Returns a dictionary containing the name, title, and url of each config file
Gets a list of book configurations hosted on the OpenDSA server Returns a dictionary containing the name title and url of each config file