Class: StormForge::Dsl::TestCase::Session
- Inherits:
-
Object
- Object
- StormForge::Dsl::TestCase::Session
- Includes:
- ActiveModel::Serializers::JSON, ActiveModel::Validations, AttributeAccess
- Defined in:
- lib/stormforge/dsl/test_case/session.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#data_sources ⇒ Object
readonly
Returns the value of attribute data_sources.
Instance Method Summary collapse
- #available_attributes ⇒ Object
-
#initialize(name, probability, data_sources, callable = nil, &block) ⇒ Session
constructor
A new instance of Session.
- #pick(what) ⇒ Object
- #serializable_hash(*args) ⇒ Object
- #wait(seconds) ⇒ Object
Methods included from AttributeAccess
#method_missing, #respond_to_missing?
Constructor Details
#initialize(name, probability, data_sources, callable = nil, &block) ⇒ Session
Returns a new instance of Session.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 17 def initialize(name, probability, data_sources, callable=nil, &block) @attributes = { name: name, probability: probability, steps: [] } @data_sources = data_sources instance_eval(&(callable || block)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class StormForge::Dsl::TestCase::AttributeAccess
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 8 def attributes @attributes end |
#data_sources ⇒ Object (readonly)
Returns the value of attribute data_sources.
8 9 10 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 8 def data_sources @data_sources end |
Instance Method Details
#available_attributes ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 28 def available_attributes [ :name, :probability, :description, :steps ] end |
#pick(what) ⇒ Object
50 51 52 53 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 50 def pick(what) raise "DataSource #{what} not defined!" unless @data_sources.sources[what] @data_sources.sources[what].next end |
#serializable_hash(*args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 55 def serializable_hash(*args) hash = super hash[:data_sources_usage] = if data_sources.present? data_sources.sources.each_with_object({}) do |(name, source), memo| memo[name] = source.count end else {} end hash end |
#wait(seconds) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/stormforge/dsl/test_case/session.rb', line 43 def wait(seconds) @attributes[:steps] << { action: :wait, duration: seconds } end |