Class: StormForge::Dsl::TestCase::DataSource::FileFixture

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, ActiveModel::Validations, AttributeAccess
Defined in:
lib/stormforge/dsl/test_case/data_source/file_fixture.rb

Defined Under Namespace

Classes: FixtureSourceValidator, ItemProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeAccess

#method_missing, #respond_to_missing?

Constructor Details

#initialize(name, options) ⇒ FileFixture

Returns a new instance of FileFixture.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 51

def initialize(name, options)
  @attributes = {
    name: name
  }.merge(options)

  unless @attributes[:simple_file]
    @attributes[:order] = :sequentially unless @attributes[:order]
    @attributes[:delimiter] = ";" unless @attributes[:delimiter]
  end

  @sequence = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class StormForge::Dsl::TestCase::AttributeAccess

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



33
34
35
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 33

def attributes
  @attributes
end

Instance Method Details

#as_json(*args) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 79

def as_json(*args)
  hash = super
  hash[:type] = "file_fixture"
  hash[:md5_hash] = self.md5_hash
  hash[:source] = File.basename(self.source)
  hash
end

#available_attributesObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 64

def available_attributes
  [
    :name,
    :source,
    :fields,
    :delimiter,
    :order,
    :simple_file
  ]
end

#countObject



100
101
102
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 100

def count
  @sequence
end

#md5_hashObject



75
76
77
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 75

def md5_hash
  ::Digest::MD5.file(self.source).hexdigest if File.exist? self.source
end

#nextObject



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/stormforge/dsl/test_case/data_source/file_fixture.rb', line 87

def next
  args = {
    n: name,
    seq: (@sequence += 1)
  }

  if fields.present?
    ItemProxy.new(args, fields)
  else
    StormForge::Dsl::TestCase::DataSource.build_marker("FILEFIXTURE", args)
  end
end