Class: SimpleFileStore::Base
- Inherits:
-
MiniBlankSlate
- Object
- MiniBlankSlate
- SimpleFileStore::Base
- Defined in:
- lib/simple_file_store/simple_file_store.rb
Constant Summary collapse
- KnownFeatures =
Dir.glob(File.join(File.dirname(__FILE__), '*_file_store.rb')).map do |f| f =~ %r|.*/([a-z]+)_file_store.rb$| $1 && $1 != 'simple' ? $1 : nil end.compact.freeze
- FileStoreRoot =
"fstore".freeze
- Separator =
"-".freeze
Constants inherited from MiniBlankSlate
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#root ⇒ Object
Returns the value of attribute root.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#usec ⇒ Object
Returns the value of attribute usec.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Base
constructor
A new instance of Base.
- #open(flag = 'r+', &block) ⇒ Object
- #path ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Base
Returns a new instance of Base.
73 74 75 76 77 78 |
# File 'lib/simple_file_store/simple_file_store.rb', line 73 def initialize(args = {}) init_root! validate! load_arguments(args) load_or_store! end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
47 48 49 |
# File 'lib/simple_file_store/simple_file_store.rb', line 47 def content @content end |
#content_type ⇒ Object
Returns the value of attribute content_type.
46 47 48 |
# File 'lib/simple_file_store/simple_file_store.rb', line 46 def content_type @content_type end |
#file_name ⇒ Object
Returns the value of attribute file_name.
48 49 50 |
# File 'lib/simple_file_store/simple_file_store.rb', line 48 def file_name @file_name end |
#root ⇒ Object
Returns the value of attribute root.
46 47 48 |
# File 'lib/simple_file_store/simple_file_store.rb', line 46 def root @root end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
46 47 48 |
# File 'lib/simple_file_store/simple_file_store.rb', line 46 def @timestamp end |
#usec ⇒ Object
Returns the value of attribute usec.
46 47 48 |
# File 'lib/simple_file_store/simple_file_store.rb', line 46 def usec @usec end |
Class Method Details
.features(*args) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/simple_file_store/simple_file_store.rb', line 63 def features(*args) args = args.flatten.compact raise ArgumentError, "Unknown feature" unless args.all?{|a| KnownFeatures.include?(a.to_s)} args.each do |a| instance_eval { include "#{a}_file_store".classify.constantize } end end |
.file_name_tokens(*args) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/simple_file_store/simple_file_store.rb', line 51 def file_name_tokens(*args) @file_name_tokens ||= [] unless args.empty? @file_name_tokens.concat(args) args.each do |token| next if [:timestamp, :usec].include?(token.to_sym) instance_eval { attr_accessor token } end end @file_name_tokens end |
Instance Method Details
#open(flag = 'r+', &block) ⇒ Object
104 105 106 107 108 |
# File 'lib/simple_file_store/simple_file_store.rb', line 104 def open(flag = 'r+', &block) path.dirname.mkpath FileUtils.touch(path) File.open(path, flag, &block) end |
#path ⇒ Object
80 81 82 |
# File 'lib/simple_file_store/simple_file_store.rb', line 80 def path root.join(self.class.name.tableize, file_name) end |