Module: FilesystemViews

Included in:
FilesystemEnv::GlueEnv
Defined in:
lib/glue_envs/filesystem_glue_env.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_my_category(moab_data, user_datastore_location, match_keys) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# 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

Instance Method Details

#call_view(field_name, moab_data, namespace_key, user_datastore_location, match_key, view_name = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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