Class: Hackpad::Cli::Pad
- Inherits:
-
Object
- Object
- Hackpad::Cli::Pad
- Defined in:
- lib/hackpad/cli/pad.rb
Instance Attribute Summary collapse
-
#cached_at ⇒ Object
readonly
Returns the value of attribute cached_at.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#guest_policy ⇒ Object
readonly
Returns the value of attribute guest_policy.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#moderated ⇒ Object
readonly
Returns the value of attribute moderated.
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #chars ⇒ Object
-
#initialize(id) ⇒ Pad
constructor
A new instance of Pad.
- #lines ⇒ Object
- #load(ext, refresh = false) ⇒ Object
- #load_from_provider(klass, ext) ⇒ Object
- #load_options(options) ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(id) ⇒ Pad
Returns a new instance of Pad.
17 18 19 |
# File 'lib/hackpad/cli/pad.rb', line 17 def initialize(id) @id = id end |
Instance Attribute Details
#cached_at ⇒ Object (readonly)
Returns the value of attribute cached_at.
15 16 17 |
# File 'lib/hackpad/cli/pad.rb', line 15 def cached_at @cached_at end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
15 16 17 |
# File 'lib/hackpad/cli/pad.rb', line 15 def content @content end |
#guest_policy ⇒ Object (readonly)
Returns the value of attribute guest_policy.
15 16 17 |
# File 'lib/hackpad/cli/pad.rb', line 15 def guest_policy @guest_policy end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/hackpad/cli/pad.rb', line 15 def id @id end |
#moderated ⇒ Object (readonly)
Returns the value of attribute moderated.
15 16 17 |
# File 'lib/hackpad/cli/pad.rb', line 15 def moderated @moderated end |
Instance Method Details
#cached? ⇒ Boolean
58 59 60 |
# File 'lib/hackpad/cli/pad.rb', line 58 def cached? Store.exist? 'meta', @id end |
#chars ⇒ Object
25 26 27 |
# File 'lib/hackpad/cli/pad.rb', line 25 def chars @content.length if @content end |
#lines ⇒ Object
29 30 31 |
# File 'lib/hackpad/cli/pad.rb', line 29 def lines @content.lines.count if @content end |
#load(ext, refresh = false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hackpad/cli/pad.rb', line 33 def load(ext, refresh = false) fail UnknownFormat unless FORMATS.include? ext fail UndefinedPad unless @id if refresh || !Store.exist?(ext, @id) load_from_provider Api, ext Store.save(self, ext) Store.(@id, @options) else load_from_provider Store, ext end end |
#load_from_provider(klass, ext) ⇒ Object
45 46 47 48 49 |
# File 'lib/hackpad/cli/pad.rb', line 45 def load_from_provider(klass, ext) @content = klass.read @id, ext @options = klass.(@id) @options end |
#load_options(options) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/hackpad/cli/pad.rb', line 51 def () @guest_policy = ['options']['guestPolicy'] @moderated = ['options']['isModerated'] ['cached_at'] ||= Time.now @cached_at = ['cached_at'] end |
#title ⇒ Object
21 22 23 |
# File 'lib/hackpad/cli/pad.rb', line 21 def title @title ||= (@content.lines.first.strip if @content) end |