Module: Stratagem

Defined in:
lib/stratagem.rb,
lib/stratagem/client.rb,
lib/stratagem/logger.rb,
lib/stratagem/snapshot.rb,
lib/stratagem/site_crawler.rb,
lib/stratagem/model_builder.rb,
lib/stratagem/authentication.rb,
lib/stratagem/configuration/core.rb,
lib/stratagem/configuration/auth_auth.rb,
lib/generators/stratagem/install/install_base.rb,
lib/generators/stratagem/install/install_generator.rb

Defined Under Namespace

Modules: AutoMock, Command, Commands, Configuration, Crawler, Generators, Instrumentation, Model Classes: Authentication, Client, InstallGenerator, Logger, ModelBuilder, SiteCrawler, Snapshot

Class Method Summary collapse

Class Method Details

.analyzeObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/stratagem.rb', line 116

def analyze
  unless (@@running)
    @@running = true
    Thread.new {
      begin
        if (configuration.use_transactional_crawling)
          ActiveRecord::Base.connection.increment_open_transactions
          ActiveRecord::Base.connection.transaction_joinable = false
          ActiveRecord::Base.connection.begin_db_transaction
        end

        prescan.call unless prescan.nil?
        authentication = Stratagem::Authentication.instance
        snapshot = Stratagem::Snapshot.create(authentication.project)
        Stratagem::Client.new(authentication).send(snapshot)
      rescue Exception
        puts $!.message
        puts $!.backtrace
      ensure
        if (configuration.use_transactional_crawling)
          ActiveRecord::Base.connection.decrement_open_transactions
          ActiveRecord::Base.connection.rollback_db_transaction
        end

        complete
      end
    }
  end
end

.completeObject



111
112
113
114
# File 'lib/stratagem.rb', line 111

def complete
  Stratagem.logger.phase('complete')
  @@blocker.notify
end

.configurationObject



21
22
23
# File 'lib/stratagem.rb', line 21

def configuration
  @@configuration
end

.configure(&block) ⇒ Object



15
16
17
18
19
# File 'lib/stratagem.rb', line 15

def configure(&block)
  @@configuration = Configuration::Core.new
  block.call(@@configuration) if block
  @@configuration
end

.domainObject



66
67
68
69
70
71
72
# File 'lib/stratagem.rb', line 66

def domain
  if local?
    'localhost:3000'
  else
    'stratagemapp.com'
  end
end

.error(error) ⇒ Object



99
100
101
# File 'lib/stratagem.rb', line 99

def error(error)
  errors << error
end

.errorsObject



103
104
105
# File 'lib/stratagem.rb', line 103

def errors
  @errors ||= []
end

.initObject



53
54
55
56
57
58
59
60
# File 'lib/stratagem.rb', line 53

def init
  load_dependencies

  @@prescan = nil
  @@blocker = Blocker.new
  @@running = false
  @@session_id = Time.now.to_f.to_s # the interface uses this to determine which instance of the client it's talking to
end

.load_dependenciesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/stratagem.rb', line 29

def load_dependencies
  require 'haml'
  require 'launchy'
  require 'redparse'
  require 'stratagem/rack_hack'
  require 'stratagem/blocker'
  require 'stratagem/logger'
  require 'stratagem/extensions'
  require 'stratagem/instrumentation'

  require 'stratagem/model'
  require 'stratagem/auto_mock'

  require 'stratagem/authentication'
  require 'stratagem/client'
  require 'stratagem/command'
  require 'stratagem/model_builder'
  require 'stratagem/crawler'
  require 'stratagem/site_crawler'
  require 'stratagem/snapshot'

  require 'stratagem/commands'
end

.local?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/stratagem.rb', line 147

def local?
  ENV['local'] && ENV['local'] == 'true'
end

.loggerObject



95
96
97
# File 'lib/stratagem.rb', line 95

def logger
  Stratagem::Logger.instance
end

.prescan(&block) ⇒ Object



25
26
27
# File 'lib/stratagem.rb', line 25

def prescan(&block)
  @@prescan = block if block
end

.rails_2?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/stratagem.rb', line 87

def rails_2?
  rails_version.between?(200, 299)
end

.rails_3?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/stratagem.rb', line 83

def rails_3?
  rails_version.between?(300, 399)
end

.rails_versionObject



74
75
76
77
78
79
80
81
# File 'lib/stratagem.rb', line 74

def rails_version
  @@rails_version ||= begin
    rails_version = Rails.version.split('.').map {|v| v.size > 1 ? 9 : v.to_i }
    rails_version << 0 while rails_version.size < 3
    rails_version.pop while rails_version.size > 3
    rails_version.join.to_i
  end
end

.session_idObject



91
92
93
# File 'lib/stratagem.rb', line 91

def session_id
  @@session_id
end

.ssl?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/stratagem.rb', line 62

def ssl?
  !local?
end

.wait_for_completionObject



107
108
109
# File 'lib/stratagem.rb', line 107

def wait_for_completion
  @@blocker.wait
end