Class: Smooth::Application

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

Defined Under Namespace

Classes: User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Application

Returns a new instance of Application.



8
9
10
11
12
13
14
15
16
17
# File 'lib/smooth/application.rb', line 8

def initialize(options = {}, &block)
  @options = options
  instance_eval(&block) if block_given?

  config do
    self.root = options[:root]
  end

  boot unless options[:defer]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/smooth/application.rb', line 3

def options
  @options
end

Instance Method Details

#apiObject



32
33
34
# File 'lib/smooth/application.rb', line 32

def api
  @api ||= Smooth(options[:api] || :default)
end

#bootObject



58
59
60
61
62
63
64
# File 'lib/smooth/application.rb', line 58

def boot
  @boot ||= begin
              Smooth.active_record.establish_connection
              load_models
              Smooth.eager_load_from_app_folders
            end
end

#command(*args) ⇒ Object



48
49
50
# File 'lib/smooth/application.rb', line 48

def command(*args)
  smooth.send(:run_command, *args)
end

#config(&block) ⇒ Object



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

def config(&block)
  Smooth.config(&block)
end

#consoleObject



23
24
25
26
# File 'lib/smooth/application.rb', line 23

def console
  require 'pry'
  Pry.start(self, {})
end

#load_modelsObject



52
53
54
55
56
# File 'lib/smooth/application.rb', line 52

def load_models
  Dir[config.models_path.join('**/*.rb')].each do |f|
    require config.models_path.join(f)
  end
end

#query(*args) ⇒ Object



44
45
46
# File 'lib/smooth/application.rb', line 44

def query(*args)
  smooth.send(:query, *args)
end

#resource(*args, &_block) ⇒ Object



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

def resource(*args, &_block)
  api.send(:resource, *args)
end

#smoothObject



36
37
38
# File 'lib/smooth/application.rb', line 36

def smooth
  @smooth ||= api.as(system_user)
end

#system_userObject



28
29
30
# File 'lib/smooth/application.rb', line 28

def system_user
  @system_user ||= User.new(email: '[email protected]', role: 'system')
end