Module: Rails::DSL::ActionDispatchRouteEXT

Defined in:
lib/rails-dsl/routes_ext.rb

Defined Under Namespace

Modules: Helpers

Instance Method Summary collapse

Instance Method Details

#mount_by(opts = {}) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/rails-dsl/routes_ext.rb', line 118

def mount_by(opts={})
  opts = Helpers.process_opts(opts)

  if opts[:class]
    mount_controller opts
  end

end

#mount_controller(opts = {}) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/rails-dsl/routes_ext.rb', line 127

def mount_controller(opts={})

  opts[:pim].each do |method_name|

    # #> override methods if instance method variable detected, and will passed as input from params
    # begin
    #   var= opts[:class].constantize.instance_method(method_name)
    #   unless var.parameters.select{|ary|(ary[0] ==:req)}.empty?
    #     define_method(method_name) do
    #       var.bind(self).call(*var.parameters.select{|ary|(ary[0] == :req)}.map{|ary| ary[1] }.map{ |param_key| params[param_key] })
    #     end
    #   end
    # end

    #> build path by method name
    method_to_use= nil
    [:get,:post,:put,:delete,:options].each do |pre_spec_method_call_type|
      if opts[pre_spec_method_call_type].include?(method_name)
        method_to_use ||= pre_spec_method_call_type
      end
    end
    method_to_use ||= :match

    url_path = opts[:urls][method_name].nil? ? "/#{method_name}" : opts[:urls][method_name].to_s

    self.__send__ method_to_use,
                  "#{url_path}#{Helpers.array_to_url_params(opts[:params],method_name)}",
                  {to: "#{opts[:short_class_name]}##{method_name}", defaults: opts[:defaults].dup }

  end

  return nil

end

#mount_controller_with_render(*args) ⇒ Object Also known as: mount_rendered_controller



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rails-dsl/routes_ext.rb', line 162

def mount_controller_with_render *args

  opts= Rails::DSL::ActionDispatchRouteEXT::Helpers.process_args(*args)
  conv_params= []

  # make last value return as value object rendered as the specific format
  opts[:class].class_eval do

    opts[:pim].each do |sym|



    end

  end

  # mount controller methods
  mount_controller *args,*conv_params #, { defaults: {format: :json} }

  return nil

end