Module: Apitest

Defined in:
lib/apitest.rb,
lib/apitest/error.rb,
lib/apitest/engine.rb,
lib/apitest/reader.rb,
lib/apitest/version.rb,
lib/apitest/module_error.rb,
lib/apitest/service_error.rb,
app/jobs/apitest/application_job.rb,
app/helpers/apitest/apitest_helper.rb,
app/models/apitest/application_record.rb,
app/helpers/apitest/application_helper.rb,
app/mailers/apitest/application_mailer.rb,
app/controllers/apitest/apitest_controller.rb,
app/controllers/apitest/application_controller.rb

Defined Under Namespace

Modules: ApitestHelper, ApplicationHelper, Error, ModelError, ServiceError Classes: ApitestController, ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Engine, Reader

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.api_dir(dir = nil) ⇒ Object



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

def api_dir(dir = nil)
  @api_dir = dir if dir
  @api_dir
end

.default_types(default_types = []) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/apitest.rb', line 31

def default_types(default_types = [])
  return @default_types if default_types.blank?
  @default_types = {}
  default_types.each do |type|
    @default_types[type] = []
  end
  @default_types
end

.public_required(public_required = []) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/apitest.rb', line 40

def public_required(public_required = [])
  return @public_required if public_required.blank?
  @public_required = []
  public_required.each do |need|
    n = { need => {required: true }}
    @public_required.push n
  end
  @public_required
end

.set_headersObject



55
56
57
# File 'lib/apitest.rb', line 55

def set_headers
  @token_setting[:set] && @token_setting[:set][1] ? {@token_setting[:set][1] => ''} : {}
end

.start_server_log_listenObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/apitest.rb', line 59

def start_server_log_listen
  Process.detach(
    fork do
      p 'Kill Apitest WebSocket Process ...'
      `lsof -i :9527 |awk '$1 == "ruby"  {print $2}' |xargs kill -9`
      begin
        filename = "#{Rails.root}/log/#{Rails.env}.log"

        EventMachine.run do
          WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => 9527) do |ws|
            proc = Proc.new { |line|
              ws.send Ansi::To::Html.new(line.strip).to_html.strip
            }
            EventMachine::file_tail(filename, Reader, &proc)
          end
          p 'Start Apitest WebSocket Process !'
        end
      rescue Exception => e
        retry
      end
    end
  )
end

.theme(theme = nil) ⇒ Object



26
27
28
29
# File 'lib/apitest.rb', line 26

def theme(theme = nil)
  @theme = theme if theme
  @theme
end

.token_setting(setting = nil) ⇒ Object



50
51
52
53
# File 'lib/apitest.rb', line 50

def token_setting(setting = nil)
  @token_setting = setting if setting
  @token_setting
end