Class: Parklife::Application
- Inherits:
-
Object
- Object
- Parklife::Application
- Defined in:
- lib/parklife/application.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #after_build(&block) ⇒ Object
- #before_build(&block) ⇒ Object
- #build ⇒ Object
- #configure {|config| ... } ⇒ Object
- #crawler ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #load_Parkfile(path) ⇒ Object
- #routes(&block) ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
13 14 15 16 17 18 |
# File 'lib/parklife/application.rb', line 13 def initialize @config = Config.new @route_set = RouteSet.new @after_build_callbacks = [] @before_build_callbacks = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/parklife/application.rb', line 11 def config @config end |
Instance Method Details
#after_build(&block) ⇒ Object
20 21 22 |
# File 'lib/parklife/application.rb', line 20 def after_build(&block) @after_build_callbacks << block end |
#before_build(&block) ⇒ Object
24 25 26 |
# File 'lib/parklife/application.rb', line 24 def before_build(&block) @before_build_callbacks << block end |
#build ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/parklife/application.rb', line 28 def build raise BuildDirNotDefinedError if config.build_dir.nil? raise RackAppNotDefinedError if config.app.nil? if Dir.exist?(config.build_dir) FileUtils.rm_rf(Pathname.new(config.build_dir).children) else Dir.mkdir(config.build_dir) end @before_build_callbacks.each do |callback| callback.call(self) end crawler.start @after_build_callbacks.each do |callback| callback.call(self) end end |
#configure {|config| ... } ⇒ Object
49 50 51 |
# File 'lib/parklife/application.rb', line 49 def configure yield config end |
#crawler ⇒ Object
53 54 55 |
# File 'lib/parklife/application.rb', line 53 def crawler @crawler ||= Crawler.new(config, @route_set) end |
#load_Parkfile(path) ⇒ Object
57 58 59 60 |
# File 'lib/parklife/application.rb', line 57 def load_Parkfile(path) raise ParkfileLoadError.new(path) unless File.exist?(path) load path end |
#routes(&block) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/parklife/application.rb', line 62 def routes(&block) if block_given? @route_set.instance_eval(&block) else @route_set end end |