simpex 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simpex (0.0.5)
4
+ simpex (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -3,7 +3,8 @@ class ImpexResult
3
3
  attr_writer :memory_safe, :max_type_entries_in_tree
4
4
 
5
5
  def initialize(dest_folder)
6
- raise "Given dest folder #{dest_folder} is either nil or does not exist!" if dest_folder.nil? || !Dir.exist?(dest_folder)
6
+ raise "Given dest folder #{dest_folder} is either nil or does not exist!" if dest_folder.nil? ||
7
+ !Dir.exist?(dest_folder)
7
8
  @dest_folder = dest_folder
8
9
  @types = []
9
10
  @max_type_entries_in_tree = 2000
@@ -49,7 +50,6 @@ class ImpexResult
49
50
 
50
51
  private
51
52
  def validate_macros
52
-
53
53
  #collect all macros from all types
54
54
  @macros = @types.inject([]) do |result, type|
55
55
  type.macros.each do |macro|
@@ -57,11 +57,13 @@ class ImpexResult
57
57
  end
58
58
  result
59
59
  end
60
-
61
60
  #make sure each macro is used in at least one type
62
61
  @macros.each do |macro|
63
- if @types.none? {|type| type.attributes.include?(macro)}
64
- raise ArgumentError.new "the macro #{macro} is never used in all declared types"
62
+ macro_key = macro.split("=").first
63
+ not_used_in_types = @types.none? {|type| type.attributes.include?(macro_key)}
64
+ not_used_in_macros = @macros.none? {|m| !m.eql?(macro) && m.include?(macro_key)}
65
+ if not_used_in_types && not_used_in_macros
66
+ raise ArgumentError.new "the macro #{macro} is never used in all declared types and macros"
65
67
  end
66
68
  end
67
69
  end
@@ -75,7 +77,7 @@ class ImpexResult
75
77
  end
76
78
  puts "writing complete result to the file #{file_name}"
77
79
  result_file_name = File.basename(result_file_name)
78
- raise "You gave the directory #{result_file_name} instead of a single file" if File.directory?(result_file_name)
80
+ raise "You directory '#{result_file_name}' instead of a single file" if File.directory?(result_file_name)
79
81
  File.open(file_name, "w") do |f|
80
82
  all_macros = []
81
83
  @types.each do |type|
@@ -118,7 +120,8 @@ class ImpexResult
118
120
  def check_for_impexify
119
121
  if @memory_safe
120
122
  if @global_enties_number > @max_type_entries_in_tree
121
- puts "impexifying all entries since global entries #{@global_enties_number} is bigger then max #{@max_type_entries_in_tree}"
123
+ puts "impexifying all entries since global entries #{@global_enties_number} is bigger
124
+ then max #{@max_type_entries_in_tree}"
122
125
  self.impexify
123
126
  end
124
127
  end
@@ -27,7 +27,7 @@ class Type
27
27
  raise ArgumentError.new "In the type '#{name}', you are using a macro but no macros are given at all, pass the macros as an array to the type constructor."
28
28
  end
29
29
  if @macros.none?{|m| m.split("=").first == attribute.split("[").first}
30
- raise ArgumentError.new "In the type #{name}, you are using a macro that is not defined: #{attribute}, declared macros are #{@macros.inspect}"
30
+ raise ArgumentError.new "In the type '#{name}', you are using the macro '#{attribute}' that is not defined, defined macros are #{@macros.inspect}"
31
31
  end
32
32
  end
33
33
  end
@@ -1,4 +1,4 @@
1
1
  module Simpex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
4
4
 
@@ -28,20 +28,17 @@ class TestResult < Test::Unit::TestCase
28
28
 
29
29
  def test_should_recognize_not_used_macros
30
30
  macros = []
31
- macros << "$firstmacro"
32
- macros << "$secondmacro"
31
+ macros << "$variableUsedByMacros=someThing()"
32
+ macros << "$firstmacro=catalogversion[unique=true,default=$variableUsedByMacros:Staged]"
33
+ macros << "$secondmacro=something"
33
34
 
34
35
  @category_type = Type.new("Category", %w{code[unique=true] name[lang=de]}, macros)
35
36
  @product_type = Type.new("Product", %w{code[unique=true] name[lang=en]}, macros)
36
-
37
37
  result = ImpexResult.new(@impex_dest_dir)
38
38
  result << @category_type
39
39
  result << @product_type
40
-
41
-
42
40
  entry = TypeEntry.new(@product_type, %w{555 myproduct555})
43
41
  entry = TypeEntry.new(@category_type, %w{555 mycategory})
44
-
45
42
  assert_raises ArgumentError do
46
43
  result.impexify("result.csv", false)
47
44
  end
@@ -55,12 +52,15 @@ class TestResult < Test::Unit::TestCase
55
52
  result.impexify("result.csv", false)
56
53
  end
57
54
 
55
+ macros << "$neverUsed=someThing()"
58
56
  @product_type = Type.new("Product", %w{code[unique=true] name[lang=en] $firstmacro}, macros)
59
57
  @category_type = Type.new("Category", %w{code[unique=true] name[lang=de] $secondmacro}, macros)
60
58
  result = ImpexResult.new(@impex_dest_dir)
61
59
  result << @category_type
62
60
  result << @product_type
63
- result.impexify("result.csv", false)
61
+ assert_raises ArgumentError do
62
+ result.impexify("result.csv", false)
63
+ end
64
64
  end
65
65
 
66
66
  def test_should_write_the_impex_resupt_to_the_given_folder
@@ -96,7 +96,8 @@ class TestResult < Test::Unit::TestCase
96
96
  catalog_type = Type.new("Catalog", %w{id[unique=true] name[lang=de] name[lang=en] defaultCatalog})
97
97
  catalog = TypeEntry.new(catalog_type, %w{simpex_catalog SimpexCatalog SimpexCatalog true})
98
98
 
99
- catalog_version_type = Type.new("CatalogVersion", %w{catalog(id)[unique=true] version[unique=true] active defaultCurrency(isocode)})
99
+ catalog_version_type = Type.new("CatalogVersion", %w{catalog(id)[unique=true] version[unique=true]
100
+ active defaultCurrency(isocode)})
100
101
  TypeEntry.new(catalog_version_type, [catalog.id, "online", "true", "EUR"])
101
102
 
102
103
  result = ImpexResult.new(impex_dest_dir)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: