Class: PivotalShell::Cache
- Inherits:
-
Object
- Object
- PivotalShell::Cache
- Defined in:
- lib/pivotal_shell/cache.rb,
lib/pivotal_shell/cache/user.rb,
lib/pivotal_shell/cache/story.rb
Defined Under Namespace
Constant Summary collapse
- STORY_ATTRIBUTES =
%w(requested_by_id name id current_state accepted_at labels url estimate description created_at owned_by_id story_type)
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(filename) ⇒ Cache
constructor
A new instance of Cache.
- #inspect ⇒ Object
- #refresh ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(filename) ⇒ Cache
Returns a new instance of Cache.
11 12 13 14 15 16 17 |
# File 'lib/pivotal_shell/cache.rb', line 11 def initialize(filename) @filename = filename @db = SQLite3::Database.new(@filename) @db.results_as_hash = true create_tables refresh_if_needed end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
9 10 11 |
# File 'lib/pivotal_shell/cache.rb', line 9 def db @db end |
Instance Method Details
#[](key) ⇒ Object
34 35 36 37 |
# File 'lib/pivotal_shell/cache.rb', line 34 def [](key) resultset = db.execute('SELECT value FROM settings WHERE name=?', key.to_s) resultset.empty? ? nil : YAML.load(resultset.first['value']) end |
#[]=(key, value) ⇒ Object
39 40 41 42 |
# File 'lib/pivotal_shell/cache.rb', line 39 def []=(key, value) db.execute('REPLACE INTO settings (name, value) VALUES (?,?)', key.to_s, YAML.dump(value)) value end |
#inspect ⇒ Object
19 20 21 |
# File 'lib/pivotal_shell/cache.rb', line 19 def inspect "#<PivotalShell::Cache #{@filename}>" end |
#refresh ⇒ Object
23 24 25 |
# File 'lib/pivotal_shell/cache.rb', line 23 def refresh load_stories(:modified_since => self[:last_updated_at]) end |
#reload ⇒ Object
27 28 29 30 31 32 |
# File 'lib/pivotal_shell/cache.rb', line 27 def reload db.execute('DELETE FROM users') db.execute('DELETE FROM stories') @users = nil load_stories end |