Class: SnippetFile
- Inherits:
-
Struct
- Object
- Struct
- SnippetFile
- Defined in:
- app/models/snippet_file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
- .file(name, collection = Dir.glob(path(name))) ⇒ Object
- .find_by_name(name) ⇒ Object (also: find)
- .paginate(options) ⇒ Object
- .path(name) ⇒ Object
- .read(name, reader = File) ⇒ Object
- .root ⇒ Object
- .suffix ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content
1 2 3 |
# File 'app/models/snippet_file.rb', line 1 def content @content end |
#name ⇒ Object
Returns the value of attribute name
1 2 3 |
# File 'app/models/snippet_file.rb', line 1 def name @name end |
Class Method Details
.all ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/models/snippet_file.rb', line 10 def all Dir.glob([root, '/','*',suffix].join('')).collect{ |file_path| name = File.basename(file_path, suffix) content = File.read(file_path) self.new(name, content) } end |
.file(name, collection = Dir.glob(path(name))) ⇒ Object
34 35 36 37 38 |
# File 'app/models/snippet_file.rb', line 34 def file(name, collection=Dir.glob(path(name))) @files ||= {} return @files[name] if @files[name] @files[name] = collection.first end |
.find_by_name(name) ⇒ Object Also known as: find
3 4 5 6 7 |
# File 'app/models/snippet_file.rb', line 3 def find_by_name(name) if file(name) self.new(name, self.read(name)) end end |
.paginate(options) ⇒ Object
18 19 20 |
# File 'app/models/snippet_file.rb', line 18 def paginate() all end |
.path(name) ⇒ Object
30 31 32 |
# File 'app/models/snippet_file.rb', line 30 def path(name) [root, '/', name, suffix].join('') end |
.read(name, reader = File) ⇒ Object
40 41 42 |
# File 'app/models/snippet_file.rb', line 40 def read(name, reader=File) reader.read(file(name)) end |
.root ⇒ Object
22 23 24 |
# File 'app/models/snippet_file.rb', line 22 def root @root ||= Rails.root.to_s + '/app/templates/snippets' end |
.suffix ⇒ Object
26 27 28 |
# File 'app/models/snippet_file.rb', line 26 def suffix '.radius' end |
Instance Method Details
#to_param ⇒ Object
45 46 47 |
# File 'app/models/snippet_file.rb', line 45 def to_param name end |
#updated_at ⇒ Object
49 50 51 52 |
# File 'app/models/snippet_file.rb', line 49 def updated_at time = File.mtime(self.class.file(name)) I18n.localize(time, :format => :timestamp) end |