Class: CabooseStore::CabooseStoreHelper
- Inherits:
-
Object
- Object
- CabooseStore::CabooseStoreHelper
- Defined in:
- lib/caboose-store/caboose_store_helper.rb
Instance Method Summary collapse
- #init_all ⇒ Object
-
#init_routes ⇒ Object
Adds the routes to the host app to point everything to caboose.
-
#initialize(app_path, force = false) ⇒ CabooseStoreHelper
constructor
A new instance of CabooseStoreHelper.
Constructor Details
#initialize(app_path, force = false) ⇒ CabooseStoreHelper
Returns a new instance of CabooseStoreHelper.
3 4 5 6 |
# File 'lib/caboose-store/caboose_store_helper.rb', line 3 def initialize(app_path, force = false) @app_path = app_path @force = force end |
Instance Method Details
#init_all ⇒ Object
8 9 10 |
# File 'lib/caboose-store/caboose_store_helper.rb', line 8 def init_all init_routes end |
#init_routes ⇒ Object
Adds the routes to the host app to point everything to caboose
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/caboose-store/caboose_store_helper.rb', line 13 def init_routes puts "Adding the caboose store routes..." filename = File.join(@app_path,'config','routes.rb') return if !File.exists?(filename) return if !@force str = "" str << "\t# Catch everything with caboose\n" str << "\tmount CabooseStore::Engine => '/'\n" file = File.open(filename, 'rb') contents = file.read file.close if (contents.index(str).nil?) arr = contents.split('end', -1) str2 = arr[0] + "\n" + str + "\nend" + arr[1] File.open(filename, 'w') {|file| file.write(str2) } end end |