Class: Palmade::Cableguy::Cabler
- Inherits:
-
Object
- Object
- Palmade::Cableguy::Cabler
- 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
-
#app_root ⇒ Object
readonly
Returns the value of attribute app_root.
-
#builds ⇒ Object
readonly
Returns the value of attribute builds.
-
#cabler ⇒ Object
readonly
Returns the value of attribute cabler.
-
#cabling_path ⇒ Object
readonly
Returns the value of attribute cabling_path.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#db_path ⇒ Object
readonly
Returns the value of attribute db_path.
-
#group ⇒ Object
Returns the value of attribute group.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#targets ⇒ Object
Returns the value of attribute targets.
Instance Method Summary collapse
- #boot ⇒ Object
- #check_requirements ⇒ Object
- #configure ⇒ Object
-
#initialize(app_root, options) ⇒ Cabler
constructor
A new instance of Cabler.
- #migrate ⇒ Object
- #require_cables(path) ⇒ Object
- #say(message, subitem = false) ⇒ Object
- #say_with_time(message) ⇒ Object
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, ) = @app_root = app_root @cabling_path = [:path] @target = [:target] @location = [:location] @builds = nil @logger = Logger.new($stdout) @targets = [ :development ] @db_path = File.join(@cabling_path, DB_DIRECTORY, "#{@target}.#{DB_EXTENSION}") if [:verbose] @logger.level = Logger::DEBUG else @logger.level = Logger::WARN end @db = Palmade::Cableguy::DB.new(self) end |
Instance Attribute Details
#app_root ⇒ Object (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 |
#builds ⇒ Object (readonly)
Returns the value of attribute builds.
6 7 8 |
# File 'lib/palmade/cableguy/cabler.rb', line 6 def builds @builds end |
#cabler ⇒ Object (readonly)
Returns the value of attribute cabler.
11 12 13 |
# File 'lib/palmade/cableguy/cabler.rb', line 11 def cabler @cabler end |
#cabling_path ⇒ Object (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 |
#database ⇒ Object (readonly)
Returns the value of attribute database.
10 11 12 |
# File 'lib/palmade/cableguy/cabler.rb', line 10 def database @database end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
15 16 17 |
# File 'lib/palmade/cableguy/cabler.rb', line 15 def db @db end |
#db_path ⇒ Object (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 |
#group ⇒ Object
Returns the value of attribute group.
17 18 19 |
# File 'lib/palmade/cableguy/cabler.rb', line 17 def group @group end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/palmade/cableguy/cabler.rb', line 9 def location @location end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/palmade/cableguy/cabler.rb', line 12 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/palmade/cableguy/cabler.rb', line 13 def end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/palmade/cableguy/cabler.rb', line 8 def target @target end |
#targets ⇒ Object
Returns the value of attribute targets.
16 17 18 |
# File 'lib/palmade/cableguy/cabler.rb', line 16 def targets @targets end |
Instance Method Details
#boot ⇒ Object
39 40 41 42 43 |
# File 'lib/palmade/cableguy/cabler.rb', line 39 def boot @database = @db.boot self end |
#check_requirements ⇒ Object
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 |
#configure ⇒ Object
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 |
#migrate ⇒ Object
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(, 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() say() result = nil time = Benchmark.measure { result = yield } say "%.4fs" % time.real, :subitem say("#{result} rows", :subitem) if result.is_a?(Integer) result end |