Class: AlphaApi::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/alpha_api/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



41
42
# File 'lib/alpha_api/application.rb', line 41

def initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/alpha_api/application.rb', line 23

def method_missing(method, *args)
  if settings.respond_to?(method)
    settings.send(method, *args)
  elsif namespace_settings.respond_to?(method)
    namespace_settings.send(method, *args)
  else
    super
  end
end

Class Method Details

.inheritable_setting(name, default) ⇒ Object



14
15
16
# File 'lib/alpha_api/application.rb', line 14

def inheritable_setting(name, default)
  NamespaceSettings.register name, default
end

.setting(name, default) ⇒ Object



10
11
12
# File 'lib/alpha_api/application.rb', line 10

def setting(name, default)
  ApplicationSettings.register name, default
end

Instance Method Details

#after_initializer!Object

Runs after the app’s initializer



67
68
69
# File 'lib/alpha_api/application.rb', line 67

def after_initializer!
  # puts 'after initializer'
end

#before_initializer!Object

Runs before the app’s initializer



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/alpha_api/application.rb', line 45

def before_initializer!
  # puts 'before initializer'
  ApiPagination.configure do |config|
    config.page_param do |params|
      if params[:page].is_a?(ActionController::Parameters) && params[:page].include?(:number)
        params[:page][:number]
      else
        1
      end
    end

    config.per_page_param do |params|
      if params[:page].is_a?(ActionController::Parameters) && params[:page].include?(:size)
        params[:page][:size]
      else
        10
      end
    end
  end
end

#namespace_settingsObject



37
38
39
# File 'lib/alpha_api/application.rb', line 37

def namespace_settings
  @namespace_settings ||= SettingsNode.build(NamespaceSettings)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/alpha_api/application.rb', line 19

def respond_to_missing?(method, include_private = false)
  [settings, namespace_settings].any? { |sets| sets.respond_to?(method) } || super
end

#settingsObject



33
34
35
# File 'lib/alpha_api/application.rb', line 33

def settings
  @settings ||= SettingsNode.build(ApplicationSettings)
end