monkey_notification 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -26,12 +26,13 @@ end
26
26
 
27
27
  PKG_FILES = FileList[
28
28
  '[a-zA-Z]*',
29
- 'lib/**/*.rb'
29
+ 'lib/**/*.rb',
30
+ 'generators/**/*.*'
30
31
  ]
31
32
 
32
33
  spec = Gem::Specification.new do |s|
33
34
  s.name = "monkey_notification"
34
- s.version = "0.0.4"
35
+ s.version = "0.0.5"
35
36
  s.author = "Alexey Vasileiv"
36
37
  s.email = "alexey.vasiliev@railsware.com"
37
38
  s.homepage = "http://railsware.com/"
@@ -0,0 +1,34 @@
1
+ # Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
2
+
3
+ Rails::Generator::Commands::Base.class_eval do
4
+ def file_contains?(relative_destination, line)
5
+ File.read(destination_path(relative_destination)).include?(line)
6
+ end
7
+ end
8
+
9
+ Rails::Generator::Commands::Create.class_eval do
10
+ def append_to(file, line)
11
+ logger.insert "#{line} appended to #{file}"
12
+ unless options[:pretend] || file_contains?(file, line)
13
+ File.open(file, "a") do |file|
14
+ file.puts
15
+ file.puts line
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ Rails::Generator::Commands::Destroy.class_eval do
22
+ def append_to(file, line)
23
+ logger.remove "#{line} removed from #{file}"
24
+ unless options[:pretend]
25
+ gsub_file file, "\n#{line}", ''
26
+ end
27
+ end
28
+ end
29
+
30
+ Rails::Generator::Commands::List.class_eval do
31
+ def append_to(file, line)
32
+ logger.insert "#{line} appended to #{file}"
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+
3
+ class MonkeyNotificationGenerator < Rails::Generator::Base
4
+
5
+ def add_options!(opt)
6
+ opt.on('-k', '--api-url=url', String, "Your Monkey URL") {|v| options[:api_url] = v}
7
+ end
8
+
9
+ def manifest
10
+ if !api_url_configured? && !options[:api_url]
11
+ puts "Must pass --api-url or create config/initializers/monkey_notification.rb"
12
+ exit
13
+ end
14
+ record do |m|
15
+ m.directory 'lib/tasks'
16
+ m.file 'monkey_notification_tasks.rake', 'lib/tasks/monkey_notification_tasks.rake'
17
+ if ['config/deploy.rb', 'Capfile'].all? { |file| File.exists?(file) }
18
+ m.append_to 'config/deploy.rb', capistrano_hook
19
+ end
20
+ if api_url_expression
21
+ m.template 'initializer.rb', 'config/initializers/monkey_notification.rb',
22
+ :assigns => {:api_url => api_url_expression}
23
+ end
24
+ end
25
+ end
26
+
27
+ def api_url_configured?
28
+ File.exists?('config/initializers/monkey_notification.rb')
29
+ end
30
+
31
+ def api_url_expression
32
+ "'#{options[:api_url]}'"
33
+ end
34
+
35
+ def capistrano_hook
36
+ IO.read(source_path('capistrano_hook.rb'))
37
+ end
38
+
39
+ end
@@ -0,0 +1,22 @@
1
+ unless ARGV.any? {|a| a =~ /^gems/}
2
+
3
+ Dir[File.join(RAILS_ROOT, 'vendor', 'gems', 'monkey_notification-*')].each do |vendored_notifier|
4
+ $: << File.join(vendored_notifier, 'lib')
5
+ end
6
+
7
+ begin
8
+ require 'monkey_notification/tasks'
9
+ rescue LoadError => exception
10
+ namespace :hoptoad do
11
+ %w(deploy test).each do |task_name|
12
+ desc "Missing dependency for monkey_notification:#{task_name}"
13
+ task task_name do
14
+ $stderr.puts "Failed to run monkey_notification:#{task_name} because of missing dependency."
15
+ $stderr.puts "You probably need to run `rake gems:install` to install the monkey_notification gem"
16
+ abort exception.inspect
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ end
@@ -2,19 +2,21 @@ class MonkeyNotificationGenerator < Rails::Generators::Base
2
2
 
3
3
  class_option :api_url, :aliases => "-k", :type => :string, :desc => "Your Monkey Url"
4
4
 
5
- source_root File.expand_path("../templates", __FILE__)
5
+ def self.source_root
6
+ File.expand_path("../../generators/monkey_notification/templates", __FILE__)
7
+ end
6
8
 
7
9
  def install
8
10
  ensure_api_url_was_configured
9
11
  append_capistrano_hook
10
- generate_initializer
12
+ generate_initializer unless api_url_configured?
11
13
  end
12
14
 
13
15
  private
14
16
 
15
17
  def ensure_api_url_was_configured
16
- if !options[:api_url]
17
- puts "Must pass --api-url"
18
+ if !api_url_configured? && !options[:api_url]
19
+ puts "Must pass --api-url or create config/initializers/monkey_notification.rb"
18
20
  exit
19
21
  end
20
22
  end
@@ -36,4 +38,8 @@ require 'monkey_notification/capistrano'
36
38
  template 'initializer.rb', 'config/initializers/monkey_notification.rb'
37
39
  end
38
40
 
41
+ def api_url_configured?
42
+ File.exists?('config/initializers/monkey_notification.rb')
43
+ end
44
+
39
45
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey_notification
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexey Vasileiv
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-13 00:00:00 +02:00
18
+ date: 2011-01-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -53,9 +53,12 @@ files:
53
53
  - lib/monkey_notification/railtie.rb
54
54
  - lib/monkey_notification.rb
55
55
  - lib/generators/monkey_notification_generator.rb
56
- - lib/generators/templates/capistrano_hook.rb
57
- - lib/generators/templates/initializer.rb
58
56
  - lib/monkey_notification_tasks.rb
57
+ - generators/monkey_notification/monkey_notification_generator.rb
58
+ - generators/monkey_notification/templates/capistrano_hook.rb
59
+ - generators/monkey_notification/templates/monkey_notification_tasks.rake
60
+ - generators/monkey_notification/templates/initializer.rb
61
+ - generators/monkey_notification/lib/insert_commands.rb
59
62
  has_rdoc: true
60
63
  homepage: http://railsware.com/
61
64
  licenses: []