Class: Brief::Briefcase
- Inherits:
-
Object
show all
- Includes:
- DSL
- Defined in:
- lib/brief/briefcase.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from DSL
#action, #define
Constructor Details
#initialize(options = {}) ⇒ Briefcase
Returns a new instance of Briefcase.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/brief/briefcase.rb', line 8
def initialize(options = {})
@options = options.to_mash
load_configuration
load_model_definitions
if Brief.case.nil?
Brief.case = self
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/brief/briefcase.rb', line 101
def method_missing(meth, *args, &block)
if repository.respond_to?(meth)
repository.send(meth, *args, &block)
else
super
end
end
|
Instance Attribute Details
#model_definitions ⇒ Object
Returns the value of attribute model_definitions.
5
6
7
|
# File 'lib/brief/briefcase.rb', line 5
def model_definitions
@model_definitions
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/brief/briefcase.rb', line 5
def options
@options
end
|
Instance Method Details
#app_path ⇒ Object
53
54
55
|
# File 'lib/brief/briefcase.rb', line 53
def app_path
uses_app? && Brief.apps_path.join(options[:app])
end
|
#config ⇒ Object
29
30
31
|
# File 'lib/brief/briefcase.rb', line 29
def config
Brief::Configuration.instance
end
|
#docs_path ⇒ Object
81
82
83
|
# File 'lib/brief/briefcase.rb', line 81
def docs_path
root.join options.fetch(:docs_path) { config.docs_path }
end
|
#load_configuration ⇒ Object
Loads the configuration for this briefcase, either from the current working directory or the configured path for the configuration file.
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/brief/briefcase.rb', line 35
def load_configuration
config_path = options.fetch(:config_path) do
root.join('brief.rb')
end
if uses_app?
instance_eval(app_path.join("config.rb").read)
end
if config_path.exist?
instance_eval(config_path.read) rescue nil
end
end
|
#load_model_definitions ⇒ Object
#model(name_or_type) ⇒ Object
Returns a model name by its human readable description or its type alias
67
68
69
70
71
72
73
74
75
|
# File 'lib/brief/briefcase.rb', line 67
def model(name_or_type)
table = Brief::Model.table
table.fetch(name_or_type) do
table.values.find do |k|
k.name == name_or_type
end
end
end
|
#models_path ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/brief/briefcase.rb', line 85
def models_path
value = options.fetch(:models_path) { config.models_path }
if value.to_s.match(/\./)
Pathname(Dir.pwd).join(value)
elsif value.to_s.match(/\//)
Pathname(value)
else
root.join(value)
end
end
|
#repository ⇒ Object
97
98
99
|
# File 'lib/brief/briefcase.rb', line 97
def repository
@repository ||= Brief::Repository.new(self, options)
end
|
#root ⇒ Object
77
78
79
|
# File 'lib/brief/briefcase.rb', line 77
def root
Pathname(options.fetch(:root) { Dir.pwd })
end
|
#use(module_type = :app, module_id) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/brief/briefcase.rb', line 19
def use(module_type=:app, module_id)
if module_type == :app && apps_path.join(module_id).exist?
config = module_type.join("config.rb")
models = module_type.join("models")
instance_eval(config.read) if config.exist?
Brief.load_modules_from(models) if models.exist?
end
end
|
#uses_app? ⇒ Boolean
49
50
51
|
# File 'lib/brief/briefcase.rb', line 49
def uses_app?
options.key?(:app) && Brief.apps_path.join(options[:app]).exist?
end
|