Class: Tzispa::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/tzispa/domain.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Domain

Returns a new instance of Domain.



12
13
14
15
16
# File 'lib/tzispa/domain.rb', line 12

def initialize(name)
  @name = name
  @root = "#{Tzispa::Environment.instance.root}/#{Tzispa::Environment.instance.apps_path}"
  instance_eval "module ::#{name.to_s.capitalize}; end"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/tzispa/domain.rb', line 10

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/tzispa/domain.rb', line 10

def root
  @root
end

Class Method Details

.load(domain, file) ⇒ Object



62
63
64
# File 'lib/tzispa/domain.rb', line 62

def self.load(domain, file)
  new(name: domain).load(file)
end

.require(domain, file) ⇒ Object



58
59
60
# File 'lib/tzispa/domain.rb', line 58

def self.require(domain, file)
  new(name: domain).require(file)
end

Instance Method Details

#include(cmod) ⇒ Object



54
55
56
# File 'lib/tzispa/domain.rb', line 54

def include(cmod)
  name.to_s.capitalize.constantize.include cmod
end

#load(file) ⇒ Object



34
35
36
# File 'lib/tzispa/domain.rb', line 34

def load(file)
  Kernel.load "#{path}/#{file}.rb"
end

#load_dir(dir = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/tzispa/domain.rb', line 46

def load_dir(dir = nil)
  rqpath = dir ? "#{path}/#{dir}" : path.to_s
  Dir["#{rqpath}/*.rb"].each do |file|
    name = file.split('/').last
    Kernel.load "#{rqpath}/#{name}"
  end
end

#pathObject



26
27
28
# File 'lib/tzispa/domain.rb', line 26

def path
  @path ||= root % name.to_s.downcase
end

#require(file) ⇒ Object



30
31
32
# File 'lib/tzispa/domain.rb', line 30

def require(file)
  Kernel.require "#{path}/#{file}"
end

#require_dir(dir = nil) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/tzispa/domain.rb', line 38

def require_dir(dir = nil)
  rqpath = dir ? "#{path}/#{dir}" : path.to_s
  Dir["#{rqpath}/*.rb"].each do |file|
    name = file.split('/').last.split('.').first
    Kernel.require "#{rqpath}/#{name}"
  end
end

#setupObject



18
19
20
21
22
23
24
# File 'lib/tzispa/domain.rb', line 18

def setup
  require_dir
  require_dir 'helpers'
  require_dir 'services'
  require_dir 'api'
  require_dir 'middleware'
end