Class: Camping::CommandsHelpers::RoutesParser

Inherits:
Object
  • Object
show all
Defined in:
lib/camping/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = Camping) ⇒ RoutesParser

Returns a new instance of RoutesParser.



100
101
102
# File 'lib/camping/commands.rb', line 100

def initialize(app = Camping)
  @parent_app, @routes = app, []
end

Class Method Details

.parse(app) ⇒ Object



96
97
98
# File 'lib/camping/commands.rb', line 96

def self.parse(app)
  new(app).parse
end

Instance Method Details

#parseObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/camping/commands.rb', line 104

def parse
  routes = @parent_app.make_camp
  collected_routes = []

  make_routes = -> (a) {

    a::X.all.map {|c|
      k = a::X.const_get(c)
      im = k.instance_methods(false).map!(&:to_s)
      methods = im & ["get", "post", "put", "patch", "delete"]
      if k.respond_to?:urls
        methods.each { |m|
          k.urls.each { |u|
            collected_routes.append Camping::CommandsHelpers::Route.new(m,c,a.to_s,u)
          }
        }
      end
    }
  }

  if @parent_app == Camping
    @parent_app::Apps.each {|a|
      make_routes.(a)
    }
  else
    make_routes.(@parent_app)
  end

  routes_collection = Camping::CommandsHelpers::RouteCollection.new(collected_routes)
end