module TinkitFileSystemViews

class ViewsMgr

Attributes

model_actor[RW]

Dependency on TinkitInfoDocEnvMethods

Public Class Methods

by_my_category(moab_data, user_datastore_location, match_keys) click to toggle source

TODO create an index to speed queries? sync issues?

# File lib/glue_envs/filesystem_glue_env.rb, line 22
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
by_parent_categories(moab_data, user_datastore_location, match_keys) click to toggle source
# File lib/glue_envs/filesystem_glue_env.rb, line 48
def self.by_parent_categories(moab_data, user_datastore_location, match_keys)
  data_file = moab_data[:moab_datastore_name]
  match_keys = [match_keys].flatten
  #all_nodes = all collection method when all is moved into here
  matching_node_data = []
  all_wkg_entries = Dir.working_entries(user_datastore_location)
  all_wkg_entries.each do |entry|
    wkg_dir = File.join(user_datastore_location, entry)
    if File.exists?(wkg_dir)
            data_file_path = File.join(wkg_dir, data_file)
            json_data  = JSON.parse(File.open(data_file_path){|f| f.read})
            node_data = HashKeys.str_to_sym(json_data)
              match_keys.each do |k|
              pc = node_data[:parent_categories]
              if pc && pc.include?(k)
                matching_node_data << node_data
                break  #we don't need to loop through each parent cat, if one already matches
              end
      end
    end
  end
  #we now have all mathcing data
  return matching_node_data
end