module FilesystemViews

Public Class Methods

by_my_category(moab_data, user_datastore_location, match_keys) click to toggle source
# File lib/glue_envs/filesystem_glue_env.rb, line 95
def self.by_my_category(moab_data, user_datastore_location, match_keys)
  data_file = moab_data[:moab_datastore_name]
  #raise "nt: #{nodetest.my_category.inspect}" if nodetest
  #raise "No category provided for search" unless my_cat
  #puts "Searching for #{my_cat.inspect}"
  match_keys = [match_keys].flatten
  my_dir = user_datastore_location
  bfss = nil
  match_keys.each do |match_key|
    my_cat_dir = match_key
    wkg_dir = File.join(my_dir, my_cat_dir)
    if File.exists?(wkg_dir)
      bfss = bfss || []
      data_file_path = File.join(wkg_dir, data_file)
      node_data  = JSON.parse(File.open(data_file_path){|f| f.read})
      #bfs = self.new(node_data)
      bfss << node_data #bfs
    end
    #return bfss   #returned as an array for compatibility with other search and node types
  #else
  #  puts "Warning: #{wkg_dir.inspect} was not found"
  #  return nil
  end
  return bfss
end

Public Instance Methods

call_view(field_name, moab_data, namespace_key, user_datastore_location, match_key, view_name = nil) click to toggle source
# File lib/glue_envs/filesystem_glue_env.rb, line 76
def call_view(field_name, moab_data, namespace_key, user_datastore_location, match_key, view_name = nil)
  data_file = moab_data[:moab_datastore_name]
  matching_records = []
  all_file_records = Dir.working_entries(user_datastore_location)
  all_file_records.each do |file_record|
    record_path = File.join(user_datastore_location, file_record)
    if File.exists?(record_path)
      data_file_path = File.join(record_path, data_file)
      json_data = JSON.parse(File.open(data_file_path){|f| f.read})
      record = HashKeys.str_to_sym(json_data)
      field_data = record[field_name]
      if field_data == match_key
        matching_records << record
      end
    end
  end
  matching_records
end