class Flor::FlorModel

Attributes

unit[RW]

Public Class Methods

from_h(h) click to toggle source
# File lib/flor/unit/models.rb, line 104
def from_h(h)

  cols = columns

  h
    .inject({}) { |r, (k, v)|
      k = k.to_sym
      if k == :data
        r[:content] = Flor.to_blob(v)
      elsif cols.include?(k)
        r[k] = v
      end
      r }
end

Public Instance Methods

data(cache=true) click to toggle source
# File lib/flor/unit/models.rb, line 68
def data(cache=true)

  cache ? (@flor_model_cache_data = _data) : _data
end
execution(reload=false) click to toggle source

Return a Flor::Execution instance linked to this model

# File lib/flor/unit/models.rb, line 42
def execution(reload=false)

  exid = @values[:exid]; return nil unless exid

  @flor_model_cache_execution = nil if reload

  @flor_model_cache_execution ||= unit.executions[exid: exid]
end
node(reload=false) click to toggle source

Returns the node hash linked to this model

# File lib/flor/unit/models.rb, line 53
def node(reload=false)

  nid = @values[:nid]; return nil unless nid
  exe = execution(reload); return nil unless exe

  nodes = exe.data['nodes']; return nil unless nodes
  nodes[nid]
end
payload(reload=false) click to toggle source
# File lib/flor/unit/models.rb, line 62
def payload(reload=false)

  nod = node(reload)
  nod ? nod['payload'] : nil
end
refresh() click to toggle source
Calls superclass method
# File lib/flor/unit/models.rb, line 73
def refresh

  instance_variables
    .each do |k|
      instance_variable_set(k, nil) \
        if k.to_s.start_with?('@flor_model_cache_')
    end

  super
end
storage() click to toggle source
# File lib/flor/unit/models.rb, line 38
def storage; unit.storage; end
to_dump_h()
Alias for: to_h
to_h() click to toggle source
# File lib/flor/unit/models.rb, line 84
def to_h

  values.inject({}) do |h, (k, v)|
    if k == :content
      h[:data] = data
    else
      h[k] = v
    end
    h
  end
end
Also aliased as: to_dump_h
unit() click to toggle source
# File lib/flor/unit/models.rb, line 37
def unit; self.class.unit; end

Protected Instance Methods

_data() click to toggle source
# File lib/flor/unit/models.rb, line 122
def _data

  d = Flor::Storage.from_blob(content)
  d['id'] = id if d.is_a?(Hash)

  d
end