class Grass::Source
Source
is smallest data object
Constants
- MIMES
Attributes
data[R]
key[RW]
Public Class Methods
[](*keys)
click to toggle source
# 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
Public Instance Methods
hide!()
click to toggle source
# File lib/grass/source.rb, line 76 def hide! self.update!(hidden: true) end
read()
click to toggle source
# File lib/grass/source.rb, line 63 def read self.binary || self.result || self.raw end
show!()
click to toggle source
# File lib/grass/source.rb, line 80 def show! self.update!(hidden: false) end
type()
click to toggle source
# File lib/grass/source.rb, line 72 def type @type ||= self.key.dir.split("/").last.singularize end
write(value)
click to toggle source
# File lib/grass/source.rb, line 67 def write value # self.file.write(value) self.update(raw: value) end
Private Instance Methods
convert_key()
click to toggle source
# File lib/grass/source.rb, line 90 def convert_key if self.key.nil? self.key = self.filepath ? Key.new(filepath: self.filepath) : Key.new(id: self.keyid) elsif self.key.is_a? String self.key = Key.new(id: self.key) end Key::ATTR_TYPES.each do |attr| unless attr == :id write_attribute(attr,self.key.public_send(attr)) end end self.keyid = self.key.id end
set_mime_type()
click to toggle source
# File lib/grass/source.rb, line 86 def set_mime_type self.mime_type ||= MIMES[self.type] || MIME::Types.type_for(self.binary.nil? ? self.format : self.filepath).first.to_s end