Class: Swat::UI::RSpecCommands::CommandsBuilder
- Inherits:
-
Object
- Object
- Swat::UI::RSpecCommands::CommandsBuilder
- Defined in:
- lib/swat/ui/rspec_commands.rb
Constant Summary collapse
- ENV_VARS =
OpenStruct.new({ rails_env: 'RAILS_ENV', db_env_number: 'TEST_ENV_NUMBER', time: 'SWAT_CURRENT_REVISION', threads_count: 'SWAT_THREADS_COUNT', thread_id: 'SWAT_CURRENT_THREAD_ID', thread_name: 'SWAT_CURRENT_THREAD_NAME', branch: 'SWAT_CURRENT_BRANCH_NAME', revision_name: 'SWAT_CURRENT_REVISION_NAME', revision_time: 'SWAT_CURRENT_REVISION_TIME', debug_mode: 'SWAT_DBG', })
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#revision_name ⇒ Object
readonly
Returns the value of attribute revision_name.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
- .current_branch ⇒ Object
- .current_revision_name ⇒ Object
- .current_revision_time ⇒ Object
- .current_scenarios ⇒ Object
- .current_thread_id ⇒ Object
- .current_thread_name ⇒ Object
- .current_threads_count ⇒ Object
- .current_user ⇒ Object
- .debug_mode? ⇒ Boolean
- .env ⇒ Object
- .now ⇒ Object
Instance Method Summary collapse
- #env ⇒ Object
-
#initialize(conf_options, time, name = nil) ⇒ CommandsBuilder
constructor
A new instance of CommandsBuilder.
- #thread_name(thread_opts, index) ⇒ Object
- #thread_scenario(thread_opts, index) ⇒ Object
- #thread_scenarios ⇒ Object
- #threads_count ⇒ Object
Constructor Details
#initialize(conf_options, time, name = nil) ⇒ CommandsBuilder
24 25 26 27 28 29 30 31 |
# File 'lib/swat/ui/rspec_commands.rb', line 24 def initialize(, time, name=nil) @config = unless @config[:threads] @config[:threads] = [{ name: 'Full' }] end @time = time @name = name || @time end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/swat/ui/rspec_commands.rb', line 8 def config @config end |
#revision_name ⇒ Object (readonly)
Returns the value of attribute revision_name.
8 9 10 |
# File 'lib/swat/ui/rspec_commands.rb', line 8 def revision_name @revision_name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
8 9 10 |
# File 'lib/swat/ui/rspec_commands.rb', line 8 def time @time end |
Class Method Details
.current_branch ⇒ Object
93 94 95 |
# File 'lib/swat/ui/rspec_commands.rb', line 93 def current_branch call_command(current_branch_command) end |
.current_revision_name ⇒ Object
77 78 79 |
# File 'lib/swat/ui/rspec_commands.rb', line 77 def current_revision_name env[ENV_VARS.revision_name] end |
.current_revision_time ⇒ Object
61 62 63 |
# File 'lib/swat/ui/rspec_commands.rb', line 61 def current_revision_time env[ENV_VARS.revision_time] ? env[ENV_VARS.revision_time].to_i : now.to_i end |
.current_scenarios ⇒ Object
81 82 83 |
# File 'lib/swat/ui/rspec_commands.rb', line 81 def current_scenarios new(Swat::UI.config., current_revision_time, current_revision_name).thread_scenarios end |
.current_thread_id ⇒ Object
73 74 75 |
# File 'lib/swat/ui/rspec_commands.rb', line 73 def current_thread_id env[ENV_VARS.thread_id].to_i end |
.current_thread_name ⇒ Object
69 70 71 |
# File 'lib/swat/ui/rspec_commands.rb', line 69 def current_thread_name env[ENV_VARS.thread_name] end |
.current_threads_count ⇒ Object
65 66 67 |
# File 'lib/swat/ui/rspec_commands.rb', line 65 def current_threads_count env[ENV_VARS.threads_count] || 1 end |
.current_user ⇒ Object
97 98 99 |
# File 'lib/swat/ui/rspec_commands.rb', line 97 def current_user call_command(current_user_command) end |
.debug_mode? ⇒ Boolean
89 90 91 |
# File 'lib/swat/ui/rspec_commands.rb', line 89 def debug_mode? !!env[ENV_VARS.debug_mode] end |
.env ⇒ Object
101 102 103 |
# File 'lib/swat/ui/rspec_commands.rb', line 101 def env ENV end |
.now ⇒ Object
85 86 87 |
# File 'lib/swat/ui/rspec_commands.rb', line 85 def now (Time.respond_to?(:now_without_mock_time) ? Time.now_without_mock_time : Time.now) end |
Instance Method Details
#env ⇒ Object
121 122 123 |
# File 'lib/swat/ui/rspec_commands.rb', line 121 def env self.class.env end |
#thread_name(thread_opts, index) ⇒ Object
56 57 58 |
# File 'lib/swat/ui/rspec_commands.rb', line 56 def thread_name(thread_opts, index) (thread_opts[:name] || "Thread##{index+1}") end |
#thread_scenario(thread_opts, index) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/swat/ui/rspec_commands.rb', line 45 def thread_scenario(thread_opts, index) { index: index, name: @name, thread: thread_name(thread_opts, index), clean: clean_command(thread_opts, index), prepare: prepare_command(thread_opts, index), run: run_command(thread_opts, index), } end |
#thread_scenarios ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/swat/ui/rspec_commands.rb', line 37 def thread_scenarios res = [] @config[:threads].each_with_index do |th, index| res << thread_scenario(th, index) end res end |
#threads_count ⇒ Object
33 34 35 |
# File 'lib/swat/ui/rspec_commands.rb', line 33 def threads_count @config[:threads].count end |