Class: TranslationStore
- Inherits:
-
Object
- Object
- TranslationStore
- Defined in:
- lib/translate/translation_store.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .instance(from_workspace = nil, to_workspace = nil) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #cleanup ⇒ Object
- #copy_finished! ⇒ Object
- #copy_finished? ⇒ Boolean
- #dump ⇒ Object
- #filename ⇒ Object
-
#initialize(w1, w2) ⇒ TranslationStore
constructor
A new instance of TranslationStore.
- #load ⇒ Object
- #tangle_finished! ⇒ Object
- #tangle_finished? ⇒ Boolean
Constructor Details
#initialize(w1, w2) ⇒ TranslationStore
Returns a new instance of TranslationStore.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/translate/translation_store.rb', line 22 def initialize(w1, w2) @w1 = w1.oid @w2 = w2.oid @store = {} @projects = {} @users = {} @objects = {} @store[:copy] = false @store[:tangle] = false load end |
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
3 4 5 |
# File 'lib/translate/translation_store.rb', line 3 def objects @objects end |
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
3 4 5 |
# File 'lib/translate/translation_store.rb', line 3 def projects @projects end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
3 4 5 |
# File 'lib/translate/translation_store.rb', line 3 def users @users end |
Class Method Details
.[](key) ⇒ Object
14 15 16 |
# File 'lib/translate/translation_store.rb', line 14 def TranslationStore.[](key) instance[key] end |
.[]=(key, value) ⇒ Object
18 19 20 |
# File 'lib/translate/translation_store.rb', line 18 def TranslationStore.[]=(key, value) instance[key] = value end |
.instance(from_workspace = nil, to_workspace = nil) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/translate/translation_store.rb', line 6 def TranslationStore.instance(from_workspace = nil, to_workspace = nil) unless defined? @@instance raise "TranslationStory needs to be initialized with two workspaces" unless from_workspace && to_workspace @@instance = new(from_workspace, to_workspace) end @@instance end |
Instance Method Details
#[](key) ⇒ Object
34 35 36 |
# File 'lib/translate/translation_store.rb', line 34 def [](key) @store[key] end |
#[]=(key, value) ⇒ Object
38 39 40 |
# File 'lib/translate/translation_store.rb', line 38 def []=(key, value) @store[key] = value end |
#cleanup ⇒ Object
76 77 78 79 |
# File 'lib/translate/translation_store.rb', line 76 def cleanup File.delete(filename) if File.exists? filename self.class.send(:remove_class_variable, :@@instance) if defined? @@instance end |
#copy_finished! ⇒ Object
42 43 44 45 |
# File 'lib/translate/translation_store.rb', line 42 def copy_finished! @store[:copy] = true dump end |
#copy_finished? ⇒ Boolean
47 48 49 |
# File 'lib/translate/translation_store.rb', line 47 def copy_finished? @store[:copy] == true end |
#dump ⇒ Object
60 61 62 63 64 |
# File 'lib/translate/translation_store.rb', line 60 def dump File.open(filename, "w+") do |f| Marshal.dump(@store, f) end end |
#filename ⇒ Object
72 73 74 |
# File 'lib/translate/translation_store.rb', line 72 def filename "translate-#{@w1}-#{@w2}" end |
#load ⇒ Object
66 67 68 69 70 |
# File 'lib/translate/translation_store.rb', line 66 def load File.open(filename, "r") do |f| @store = Marshal.load(f) end if File.exists? filename end |
#tangle_finished! ⇒ Object
51 52 53 54 |
# File 'lib/translate/translation_store.rb', line 51 def tangle_finished! @store[:tangle] = true dump end |
#tangle_finished? ⇒ Boolean
56 57 58 |
# File 'lib/translate/translation_store.rb', line 56 def tangle_finished? @store[:tangle] == true end |