class Sinatra::RestApi::Provider
Prodiver
Constants
- OPTIONS
- REQUEST
- RESPONSE
Attributes
adapter[R]
app[R]
klass[R]
options[R]
router[R]
Public Class Methods
klasses()
click to toggle source
# File lib/sinatra-rest-api/provider.rb, line 43 def self.klasses @@klasses end
new( klass, opts, app, &block )
click to toggle source
# File lib/sinatra-rest-api/provider.rb, line 19 def initialize( klass, opts, app, &block ) @klass = klass @options = opts @app = app instance_eval( &block ) if block_given? init_settings @adapter = Adapter.new( self ) @router = Router.new( self ) @router.generate_routes klass_name = klass.to_s.split( '::' ).last @@klasses[klass_name] = { class: klass, model_singular: @adapter.model_singular } decorate_model end
settings()
click to toggle source
# File lib/sinatra-rest-api/provider.rb, line 47 def self.settings @@settings end
Public Instance Methods
method_missing( name, *args, &block )
click to toggle source
Calls superclass method
# File lib/sinatra-rest-api/provider.rb, line 33 def method_missing( name, *args, &block ) super unless OPTIONS.include? name @options[name] = args[0] end
respond_to_missing?( name, include_all = false )
click to toggle source
Calls superclass method
# File lib/sinatra-rest-api/provider.rb, line 38 def respond_to_missing?( name, include_all = false ) super unless OPTIONS.include? name true end
Private Instance Methods
decorate_model()
click to toggle source
# File lib/sinatra-rest-api/provider.rb, line 53 def decorate_model # Attach meta data to model @klass.class.module_eval { attr_accessor :restapi } @klass.restapi = {} @klass.restapi[:model_singular] = @adapter.model_singular # @klass.restapi[:model_plural] = @router.plural @klass.restapi[:path_singular] = @router.path_singular @klass.restapi[:path_plural] = @router.plural # @klass.restapi_routes = routes # @klass.association_reflections[:chapters][:class_name].split( '::' ).last # => Chapter # @@klasses['Book'][:model_singular] # => book end
init_settings()
click to toggle source
# File lib/sinatra-rest-api/provider.rb, line 68 def init_settings @@settings[:request_type] = @app.restapi_request_type if defined?( @app.restapi_request_type ) && REQUEST[:content_types].include?( @app.restapi_request_type ) end