Class: Koi::Entity
- Inherits:
-
Hash
- Object
- Hash
- Koi::Entity
- Defined in:
- lib/koi.rb
Constant Summary collapse
- Status =
[:created, :completed, :removed]
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Entity
constructor
A new instance of Entity.
-
#method_missing(meth, *args, &blk) ⇒ Object
Handle things like ‘self.removed?`.
- #new? ⇒ Boolean
- #status=(st) ⇒ Object
- #sticky? ⇒ Boolean
Constructor Details
#initialize(data = {}) ⇒ Entity
Returns a new instance of Entity.
284 285 286 287 288 289 290 291 |
# File 'lib/koi.rb', line 284 def initialize data = {} self.replace status: :created, created_at: Time.now, owner: ENV['USER'], tags: [], sticky: false merge!(data) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
Handle things like ‘self.removed?`
309 310 311 312 313 314 315 |
# File 'lib/koi.rb', line 309 def method_missing meth, *args, &blk if meth.to_s.end_with?('?') && Status.include?(s = meth.to_s.chop.to_sym) self[:status] == s else super end end |
Instance Method Details
#new? ⇒ Boolean
293 294 295 |
# File 'lib/koi.rb', line 293 def new? self[:status] == :created end |
#status=(st) ⇒ Object
301 302 303 304 |
# File 'lib/koi.rb', line 301 def status= st self[:status] = st self[:"#{st}_at"] = Time.now end |
#sticky? ⇒ Boolean
297 298 299 |
# File 'lib/koi.rb', line 297 def sticky? self[:sticky] end |