Class: Appstats::Tasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/appstats/tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :appstats) {|_self| ... } ⇒ Tasks

Returns a new instance of Tasks.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/appstats/tasks.rb', line 11

def initialize(name = :appstats)
  @name = name
  base = File.expand_path('.')
  here = File.expand_path(File.dirname(File.dirname(File.dirname((__FILE__)))))
  @base = base
  @vendor = "#{here}/vendor"
  @gem_migrations = "#{here}/db/migrate"
  @app_migrate = "#{base}/db/migrate"
  @config = "#{base}/db/config.yml"
  @schema = "#{base}/db/schema.rb"
  @appstats_initializer = "#{base}/config/initializers/appstats_config.rb"
  @appstats_initializer_template = "#{here}/lib/templates/appstats_config.rb"
  @env = 'DB'
  @default_env = 'development'
  @verbose = true
  yield self if block_given?
  # Add to load_path every "lib/" directory in vendor
  Dir["#{vendor}/**/lib"].each{|p| $LOAD_PATH << p }
  define
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def base
  @base
end

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def config
  @config
end

#default_envObject

Returns the value of attribute default_env.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def default_env
  @default_env
end

#envObject

Returns the value of attribute env.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def env
  @env
end

#log_levelObject

Returns the value of attribute log_level.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def log_level
  @log_level
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def name
  @name
end

#schemaObject

Returns the value of attribute schema.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def schema
  @schema
end

#vendorObject

Returns the value of attribute vendor.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def vendor
  @vendor
end

#verboseObject

Returns the value of attribute verbose.



9
10
11
# File 'lib/appstats/tasks.rb', line 9

def verbose
  @verbose
end

Instance Method Details

#defineObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/appstats/tasks.rb', line 32

def define
  namespace :appstats do
    namespace :install do
      desc "Install the migrations for this gem (for the database aspect of the gem)"
      task :migrations do
        unless File.exists?(@app_migrate)
          puts "Creating migrate directory"
          mkdir @app_migrate
        end
        if @gem_migrations == @app_migrate
          puts "Migrations already in the right place! (#{@app_migrate})"
        else
          puts "Moving migrations files from:\n> #{@gem_migrations}\nTo\n> #{@app_migrate}"
          system "cp -R #{@gem_migrations}/* #{@app_migrate}"
        end
      end
      
      desc "Install the logger for this gem (for application instances that log statistics)"
      task :logger do
        if File.exists?(@appstats_initializer)
          puts "Initialize [#{@appstats_initializer}] already exists, creating example file [#{@appstats_initializer}.example] to see any new changes since you last installed this gem"
          system "cp -R #{@appstats_initializer_template} #{@appstats_initializer}.example"
        else
          puts "Creating default initializer [#{@appstats_initializer}]"
          system "cp -R #{@appstats_initializer_template} #{@appstats_initializer}"
        end
      end
    end
  end
end