Class: Grass::Source
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Grass::Source
show all
- Includes:
- Cache, FileSync, Render
- Defined in:
- lib/grass/source.rb
Overview
Source is smallest data object
Constant Summary
collapse
- MIMES =
{
'text' => 'text/plain',
'view' => 'text/html',
'layout' => 'text/html',
'page' => 'text/html',
'script' => 'application/javascript',
'stylesheet' => 'text/css'
}
Instance Attribute Summary collapse
Attributes included from FileSync
#file
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Cache
#cache!, clear_cache, #commit!, included, #precompile?, set_cache
Methods included from Render
#commit!, #render
Methods included from FileSync
included
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
56
57
58
|
# File 'lib/grass/source.rb', line 56
def data
@data
end
|
#key ⇒ Object
Returns the value of attribute key.
31
32
33
|
# File 'lib/grass/source.rb', line 31
def key
@key
end
|
Class Method Details
.[](*keys) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/grass/source.rb', line 35
def self.[](*keys)
keys.flatten.map{|key|
key = Key.new(id: key.dup)
file = self.find_by(locale: key.locale, dir: key.dir, path: key.path)
if file.nil? && self.fallback
file = self.find_by(locale: I18n.default_locale, dir: key.dir, path: key.path)
end
file
}.compact
end
|
Instance Method Details
#hide! ⇒ Object
76
77
78
|
# File 'lib/grass/source.rb', line 76
def hide!
self.update!(hidden: true)
end
|
#read ⇒ Object
63
64
65
|
# File 'lib/grass/source.rb', line 63
def read
self.binary || self.result || self.raw
end
|
#show! ⇒ Object
80
81
82
|
# File 'lib/grass/source.rb', line 80
def show!
self.update!(hidden: false)
end
|
#type ⇒ Object
72
73
74
|
# File 'lib/grass/source.rb', line 72
def type
@type ||= self.key.dir.split("/").last.singularize
end
|
#write(value) ⇒ Object
67
68
69
70
|
# File 'lib/grass/source.rb', line 67
def write value
self.update(raw: value)
end
|