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', user: 'SWAT_USER_NAME', })
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
Returns a new instance of CommandsBuilder.
25 26 27 28 29 30 31 32 |
# File 'lib/swat/ui/rspec_commands.rb', line 25 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
94 95 96 |
# File 'lib/swat/ui/rspec_commands.rb', line 94 def current_branch call_command(current_branch_command) rescue 'undefined' end |
.current_revision_name ⇒ Object
78 79 80 |
# File 'lib/swat/ui/rspec_commands.rb', line 78 def current_revision_name env[ENV_VARS.revision_name] end |
.current_revision_time ⇒ Object
62 63 64 |
# File 'lib/swat/ui/rspec_commands.rb', line 62 def current_revision_time env[ENV_VARS.revision_time] ? env[ENV_VARS.revision_time].to_i : now.utc.to_i end |
.current_scenarios ⇒ Object
82 83 84 |
# File 'lib/swat/ui/rspec_commands.rb', line 82 def current_scenarios new(Swat::UI.config., current_revision_time, current_revision_name).thread_scenarios end |
.current_thread_id ⇒ Object
74 75 76 |
# File 'lib/swat/ui/rspec_commands.rb', line 74 def current_thread_id env[ENV_VARS.thread_id].to_i end |
.current_thread_name ⇒ Object
70 71 72 |
# File 'lib/swat/ui/rspec_commands.rb', line 70 def current_thread_name env[ENV_VARS.thread_name] end |
.current_threads_count ⇒ Object
66 67 68 |
# File 'lib/swat/ui/rspec_commands.rb', line 66 def current_threads_count env[ENV_VARS.threads_count] || 1 end |
.current_user ⇒ Object
98 99 100 |
# File 'lib/swat/ui/rspec_commands.rb', line 98 def current_user (env[ENV_VARS.user] || call_command(current_user_command)) rescue 'undefined' end |
.debug_mode? ⇒ Boolean
90 91 92 |
# File 'lib/swat/ui/rspec_commands.rb', line 90 def debug_mode? !!env[ENV_VARS.debug_mode] end |
.env ⇒ Object
102 103 104 |
# File 'lib/swat/ui/rspec_commands.rb', line 102 def env ENV end |
.now ⇒ Object
86 87 88 |
# File 'lib/swat/ui/rspec_commands.rb', line 86 def now (Time.respond_to?(:now_without_mock_time) ? Time.now_without_mock_time : Time.now) end |
Instance Method Details
#env ⇒ Object
122 123 124 |
# File 'lib/swat/ui/rspec_commands.rb', line 122 def env self.class.env end |
#thread_name(thread_opts, index) ⇒ Object
57 58 59 |
# File 'lib/swat/ui/rspec_commands.rb', line 57 def thread_name(thread_opts, index) (thread_opts[:name] || "Thread##{index+1}") end |
#thread_scenario(thread_opts, index) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/swat/ui/rspec_commands.rb', line 46 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
38 39 40 41 42 43 44 |
# File 'lib/swat/ui/rspec_commands.rb', line 38 def thread_scenarios res = [] @config[:threads].each_with_index do |th, index| res << thread_scenario(th, index) end res end |
#threads_count ⇒ Object
34 35 36 |
# File 'lib/swat/ui/rspec_commands.rb', line 34 def threads_count @config[:threads].count end |