Class: Culpa::RoutesBuilder
- Inherits:
-
Object
- Object
- Culpa::RoutesBuilder
- Defined in:
- lib/culpa/routes_builder.rb
Overview
This class helps to build the routes. This class is used to understand and parse the DSL of the brickchains.rb file.
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#public_folder ⇒ Object
readonly
Returns the value of attribute public_folder.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #before(&blk) ⇒ Object
- #brickchain(name, *opts, &blk) ⇒ Object
- #brickchain_context(_name, &blk) ⇒ Object
- #global_prefix(prefix) ⇒ Object
- #infer(name, &blk) ⇒ Object
-
#initialize(to_eval) ⇒ RoutesBuilder
constructor
A new instance of RoutesBuilder.
- #set_public_folder(folder) ⇒ Object
Constructor Details
#initialize(to_eval) ⇒ RoutesBuilder
Returns a new instance of RoutesBuilder.
12 13 14 15 16 17 18 19 |
# File 'lib/culpa/routes_builder.rb', line 12 def initialize(to_eval) @result = {} if to_eval.is_a? String instance_eval(to_eval) else instance_eval(&to_eval) end end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/culpa/routes_builder.rb', line 9 def prefix @prefix end |
#public_folder ⇒ Object (readonly)
Returns the value of attribute public_folder.
10 11 12 |
# File 'lib/culpa/routes_builder.rb', line 10 def public_folder @public_folder end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/culpa/routes_builder.rb', line 8 def result @result end |
Instance Method Details
#before(&blk) ⇒ Object
37 38 39 40 |
# File 'lib/culpa/routes_builder.rb', line 37 def before(&blk) @before = [] unless @before @before << blk end |
#brickchain(name, *opts, &blk) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/culpa/routes_builder.rb', line 29 def brickchain(name, *opts, &blk) @result[name] = { options: opts[0], block: blk } @result[name][:before] = @before if @before end |
#brickchain_context(_name, &blk) ⇒ Object
42 43 44 |
# File 'lib/culpa/routes_builder.rb', line 42 def brickchain_context(_name, &blk) @result.merge!(RoutesBuilder.new(blk).result) end |
#global_prefix(prefix) ⇒ Object
21 22 23 |
# File 'lib/culpa/routes_builder.rb', line 21 def global_prefix(prefix) @prefix = prefix end |
#infer(name, &blk) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/culpa/routes_builder.rb', line 46 def infer(name, &blk) bta = BlockToArray.new bta.instance_eval(&blk) bta.culpa_bta_result.each do |item| route_name = "#{item}_#{name}".to_sym @result[route_name] = { class_name: name, brick_name: item } @result["#{item}_#{name}".to_sym][:before] = @before if @before end end |
#set_public_folder(folder) ⇒ Object
25 26 27 |
# File 'lib/culpa/routes_builder.rb', line 25 def set_public_folder(folder) @public_folder = folder end |