Module: Apphunk

Defined in:
lib/apphunk.rb,
lib/apphunk/proxy.rb,
lib/apphunk/config.rb,
lib/apphunk/logger.rb

Defined Under Namespace

Modules: Config, Logger, Proxy

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_optionsObject

Default options to be used for Apphunk.post. Initialized by Apphunk::Config.



13
14
15
# File 'lib/apphunk.rb', line 13

def default_options
  @default_options
end

Class Method Details

.config {|Apphunk::Config| ... } ⇒ Object

Set runtime configuration options

Yields Apphunk::Config which can be used to set configuration options in one place. See Apphunk::Config for a list of available options. These options will be available in Apphunk.default_options.

Examples

Apphunk.config do |config|
  config.token = "secret_project_token"
  config.environments = %w(staging production)
end

Yields:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/apphunk.rb', line 68

def config(&block)
  yield Apphunk::Config
  self.default_options ||= {}
  self.default_options[:tags] = Apphunk::Config.tags
  self.default_options[:token] = Apphunk::Config.token
  self.default_options[:trails] = Apphunk::Config.trails
  
  unless Apphunk::Config.environments.nil?
    self.default_options[:environments] = Apphunk::Config.environments
  end
  
  if Apphunk::Config.environment.nil? || Apphunk::Config.environment == ""
    Apphunk::Config.environment = self.default_options[:environment]
  else
    self.default_options[:environment] = Apphunk::Config.environment 
  end
end

.init_defaultsObject

Init configuration defaults



87
88
89
90
91
92
93
94
# File 'lib/apphunk.rb', line 87

def init_defaults #:nodoc:
  if env = rails_environment
    Apphunk.default_options = { 
      :environment => env,
      :environments => %w(production)
    }
  end
end

.post(message, options = {}) ⇒ Object

Sends a message to your remote inbox at apphunk.com

  • message - The body of the message

  • options - A hash of options. Merges with Apphunk.default_options

For a list of available options see Apphunk::Config.

Examples

Apphunk.post("Yet another hello world")
Apphunk.post("Tag me baby", :tags => 'apphunk, doc, examples', :trails => { :user_id => 5 })
Apphunk.post("I'm on my way to a different project", :token => 'secret_project_access_token')


28
29
30
31
# File 'lib/apphunk.rb', line 28

def post(message, options = {})
  options = (self.default_options || {}).merge(options)
  Apphunk::Proxy.send_message_to_apphunkd(message, options)
end

.post_with_options(options = {}) {|_self| ... } ⇒ Object

Send messages with predefined options in a block

Yields the Apphunk module which can be used to send messages via Apphunk.post, but temporarily merges the provided options with Apphunk.default_options. Can be used to send a bunch of messages with the same options.

  • options - A hash of options. Merges with Apphunk.default_options

For a list of available options see Apphunk::Config.

Examples

Apphunk.post_with_options(:tags => 'hello world') do |apphunk|
  apphunk.post("A messages with tags")
  apphunk.post("Another messages with the same tags")
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Apphunk)

    the object that the method was called on



49
50
51
52
53
54
# File 'lib/apphunk.rb', line 49

def post_with_options(options = {}, &block)
  preserved_defaults = self.default_options
  self.default_options = (self.default_options || {}).merge(options)
  yield self
  self.default_options = preserved_defaults
end

.rails_environmentObject

Get the current rails environment if its Rails



97
98
99
100
101
102
103
104
105
106
# File 'lib/apphunk.rb', line 97

def rails_environment #:nodoc:
  case
  when defined?(RAILS_ENV)
    RAILS_ENV
  when defined?(Rails.env)
    Rails.env
  else
    nil
  end
end