Sha256: 02faab202b879e7f46861a789d2e13ae380307c38f6425210af2cee7caefd825

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module ExtDirect
  module Service
    class Configuration
      class << self
        def generate(route_path)
          config = {}
          config['url'] = route_path
          config['type'] = "remoting"
          config['actions'] = {}
          
          services = ExtDirect::Service::Provider.fetch
          services.each do |action,methods|
            action = normalize_action(action)
            config['actions'][action] = []
            methods.each do |method,params|
              config['actions'][action] << {:name => normalize_method(method), :len => 1} if params[:type] == :remoting
            end
          end
          
          config
        end
        
        private
        
        def normalize_action(name)
          camelize(name)
        end
        
        def normalize_method(name)
          (name.to_s)[0].chr.downcase + (camelize(name.to_s))[1..-1]
        end
        
        def camelize(name)
          name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ext_direct-0.2.0 lib/ext_direct/service/configuration.rb