Class: Palmade::Cableguy::Cabler

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/palmade/cableguy/cabler.rb

Constant Summary

Constants included from Constants

Palmade::Cableguy::Constants::DB_DIRECTORY, Palmade::Cableguy::Constants::DB_EXTENSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_root, options) ⇒ Cabler

Returns a new instance of Cabler.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/palmade/cableguy/cabler.rb', line 19

def initialize(app_root, options)
  @options = options
  @app_root = app_root
  @cabling_path = @options[:path]
  @target = @options[:target]
  @location = @options[:location]
  @builds = nil
  @logger = Logger.new($stdout)
  @targets = [ :development ]
  @db_path = File.join(@cabling_path, DB_DIRECTORY, "#{@target}.#{DB_EXTENSION}")

  if @options[:verbose]
    @logger.level = Logger::DEBUG
  else
    @logger.level = Logger::WARN
  end

  @db = Palmade::Cableguy::DB.new(self)
end

Instance Attribute Details

#app_rootObject (readonly)

Returns the value of attribute app_root.



5
6
7
# File 'lib/palmade/cableguy/cabler.rb', line 5

def app_root
  @app_root
end

#buildsObject (readonly)

Returns the value of attribute builds.



6
7
8
# File 'lib/palmade/cableguy/cabler.rb', line 6

def builds
  @builds
end

#cablerObject (readonly)

Returns the value of attribute cabler.



11
12
13
# File 'lib/palmade/cableguy/cabler.rb', line 11

def cabler
  @cabler
end

#cabling_pathObject (readonly)

Returns the value of attribute cabling_path.



7
8
9
# File 'lib/palmade/cableguy/cabler.rb', line 7

def cabling_path
  @cabling_path
end

#databaseObject (readonly)

Returns the value of attribute database.



10
11
12
# File 'lib/palmade/cableguy/cabler.rb', line 10

def database
  @database
end

#dbObject (readonly)

Returns the value of attribute db.



15
16
17
# File 'lib/palmade/cableguy/cabler.rb', line 15

def db
  @db
end

#db_pathObject (readonly)

Returns the value of attribute db_path.



14
15
16
# File 'lib/palmade/cableguy/cabler.rb', line 14

def db_path
  @db_path
end

#groupObject

Returns the value of attribute group.



17
18
19
# File 'lib/palmade/cableguy/cabler.rb', line 17

def group
  @group
end

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/palmade/cableguy/cabler.rb', line 9

def location
  @location
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/palmade/cableguy/cabler.rb', line 12

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/palmade/cableguy/cabler.rb', line 13

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/palmade/cableguy/cabler.rb', line 8

def target
  @target
end

#targetsObject

Returns the value of attribute targets.



16
17
18
# File 'lib/palmade/cableguy/cabler.rb', line 16

def targets
  @targets
end

Instance Method Details

#bootObject



39
40
41
42
43
# File 'lib/palmade/cableguy/cabler.rb', line 39

def boot
  @database = @db.boot

  self
end

#check_requirementsObject



74
75
76
77
78
# File 'lib/palmade/cableguy/cabler.rb', line 74

def check_requirements
  if @configurator.include?(:requirements)
    @configurator.requirements(self, @cabling, @target)
  end
end

#configureObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/palmade/cableguy/cabler.rb', line 56

def configure
  @configurator = CableConfigurator.new
  @configurator_path = File.join(@app_root, DEFAULT_CABLEGUY_PATH)

  # checks for config/cableguy.rb
  if File.exists?(@configurator_path)
    @configurator.configure(@configurator_path)
  else
    raise MissingFile, "Required cableguy file (#{@configurator_path}) not found!"
  end

  check_requirements

  build_setups.each do |s|
    s.configure(self, @cabling, @target)
  end
end

#migrateObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/palmade/cableguy/cabler.rb', line 45

def migrate
  init_file = File.join(@cabling_path, 'init.rb')
  require init_file if File.exist?(init_file)

  say_with_time "Migrating..." do
    Migration.new(self).boot
  end

  say "Done!"
end

#require_cables(path) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/palmade/cableguy/cabler.rb', line 93

def require_cables(path)
  if path =~ /\//
    require(path)
  else
    require(File.join(@app_root, DEFAULT_CABLES_PATH, path))
  end
end

#say(message, subitem = false) ⇒ Object



80
81
82
# File 'lib/palmade/cableguy/cabler.rb', line 80

def say(message, subitem = false)
  puts "#{subitem ? "   ->" : "--"} #{message}"
end

#say_with_time(message) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/palmade/cableguy/cabler.rb', line 84

def say_with_time(message)
  say(message)
  result = nil
  time = Benchmark.measure { result = yield }
  say "%.4fs" % time.real, :subitem
  say("#{result} rows", :subitem) if result.is_a?(Integer)
  result
end