Sha256: f201ca2fe03fcd16418b5bb2705ba39d63b8b37e7a97227b57a5767bd23334c6

Contents?: true

Size: 609 Bytes

Versions: 3

Compression:

Stored size: 609 Bytes

Contents

module PushType
  class NodeField < SelectField

    include PushType::Fields::Relations 

    options template: 'relation', field_options: {}, root: '/'

    def relation_root
      root = @opts[:root] == '/' ? PushType::Node : PushType::Node.find_by_path(@opts[:root].split('/'))
      root or raise "Cannot find root node at path '#{ @opts[:root] }'"
    end   

    initialized_on_node do |object, field|
      object.class_eval do
        define_method field.name.to_sym do
          field.relation_class.find send(field.json_key) if send(field.json_key).present?
        end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
push_type_core-0.5.0.alpha.5 app/fields/push_type/node_field.rb
push_type_core-0.5.0.alpha.4 app/fields/push_type/node_field.rb
push_type_core-0.5.0.alpha.3 app/fields/push_type/node_field.rb