Class: Storexplore::Testing::DummyStore

Inherits:
Object
  • Object
show all
Defined in:
lib/storexplore/testing/dummy_store.rb

Overview

Read / Write model for a disk html store page. Every modification is directly saved to the disk, nothing remains in memory. All stores are generated in a specific subdirectory of Storexplore::Testing::Configuration #dummy_store_generation_dir / Storexplore::Testing::DummyStoreConstants #NAME

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Name of the page



62
63
64
# File 'lib/storexplore/testing/dummy_store.rb', line 62

def name
  @name
end

Class Method Details

.open(store_name) ⇒ Object

Initializes or opens a dummy store in the ‘store_name’ subdirectory



37
38
39
# File 'lib/storexplore/testing/dummy_store.rb', line 37

def self.open(store_name)
  new(root_path(store_name), store_name)
end

.uri(store_name) ⇒ Object

file:// uri for the place where the ‘store_name’ store would be created



43
44
45
# File 'lib/storexplore/testing/dummy_store.rb', line 43

def self.uri(store_name)
  "file://#{root_path(store_name)}"
end

.wipe_outObject

Deletes from disk all generated dummy stores



48
49
50
# File 'lib/storexplore/testing/dummy_store.rb', line 48

def self.wipe_out
  FileUtils.rm_rf(root_dir)
end

.wipe_out_store(store_name) ⇒ Object

Deletes from disk the ‘store_name’ dummy store



52
53
54
# File 'lib/storexplore/testing/dummy_store.rb', line 52

def self.wipe_out_store(store_name)
  FileUtils.rm_rf(root_path(store_name))
end

Instance Method Details

#add_attributes(values) ⇒ Object

Adds the specified attributes



116
117
118
# File 'lib/storexplore/testing/dummy_store.rb', line 116

def add_attributes(values)
  add([], [], HashUtils.stringify_keys(values))
end

#attributes(*args) ⇒ Object

Hash of the current attributes



109
110
111
112
113
114
# File 'lib/storexplore/testing/dummy_store.rb', line 109

def attributes(*args)
  return add_attributes(args[0]) if args.size == 1

  _name, _categories, _items, attributes = read
  HashUtils.internalize_keys(attributes)
end

#categoriesObject

Child Storexplore::Testing::DummyStore instances for existing sub categories



66
67
68
69
70
71
# File 'lib/storexplore/testing/dummy_store.rb', line 66

def categories
  _name, categories, _items, _attributes = read
  categories.map do |category_name|
    DummyStore.new("#{absolute_category_dir(category_name)}/index.html", category_name)
  end
end

#category(category_name) ⇒ Object

Child category Storexplore::Testing::DummyStore instance with the specified name. Creates it if it does not yet exist



74
75
76
77
78
# File 'lib/storexplore/testing/dummy_store.rb', line 74

def category(category_name)
  short_category_name = short_name(category_name)
  add([short_category_name], [], {})
  DummyStore.new("#{absolute_category_dir(short_category_name)}/index.html", category_name)
end

#generate(count = 1) ⇒ Object

New Storexplore::Testing::DummyStoreGenerator instance for this



125
126
127
# File 'lib/storexplore/testing/dummy_store.rb', line 125

def generate(count = 1)
  DummyStoreGenerator.new([self], count)
end

#item(item_name) ⇒ Object

Child item Storexplore::Testing::DummyStore instance with the specified name. Creates it if it does not yet exist



96
97
98
99
100
# File 'lib/storexplore/testing/dummy_store.rb', line 96

def item(item_name)
  short_item_name = short_name(item_name)
  add([], [short_item_name], {})
  DummyStore.new(absolute_item_file(short_item_name), item_name)
end

#itemsObject

Child Storexplore::Testing::DummyStore instances for existing sub items



88
89
90
91
92
93
# File 'lib/storexplore/testing/dummy_store.rb', line 88

def items
  _name, _categories, items, _attributes = read
  items.map do |item_name|
    DummyStore.new(absolute_item_file(item_name), item_name)
  end
end

#remove_attributes(*attribute_names) ⇒ Object

Removes the specified attriutes



120
121
122
# File 'lib/storexplore/testing/dummy_store.rb', line 120

def remove_attributes(*attribute_names)
  remove([], [], ArrayUtils.stringify(attribute_names))
end

#remove_category(category_name) ⇒ Object

Deletes the specified child category.



80
81
82
83
84
# File 'lib/storexplore/testing/dummy_store.rb', line 80

def remove_category(category_name)
  short_category_name = short_name(category_name)
  remove([short_category_name], [], [])
  FileUtils.rm_rf(absolute_category_dir(short_category_name))
end

#remove_item(item_name) ⇒ Object

Deletes the specified child item.



102
103
104
105
106
# File 'lib/storexplore/testing/dummy_store.rb', line 102

def remove_item(item_name)
  short_item_name = short_name(item_name)
  remove([], [short_item_name], [])
  FileUtils.rm_rf(absolute_item_file(short_item_name))
end

#uriObject

file:// uri of the page



57
58
59
# File 'lib/storexplore/testing/dummy_store.rb', line 57

def uri
  "file://#{@path}"
end