Module: DNApi::Component

Defined Under Namespace

Modules: ClassExt Classes: NoSuchComponent

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](key) ⇒ Object



29
30
31
# File 'lib/dnapi/component.rb', line 29

def self.[](key)
  components.detect {|c| c.key_id == key }
end

.componentsObject



25
26
27
# File 'lib/dnapi/component.rb', line 25

def self.components
  @components ||= []
end

.from(values) ⇒ Object



33
34
35
36
37
# File 'lib/dnapi/component.rb', line 33

def self.from(values)
  if klass = self[values.delete('key').to_sym]
    klass.new(values)
  end
end

.included(receiver) ⇒ Object



19
20
21
22
23
# File 'lib/dnapi/component.rb', line 19

def self.included(receiver)
  components << receiver
  receiver.send(:attr_accessor, :parent)
  receiver.extend ClassExt
end

Instance Method Details

#can_belong_to?(model) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/dnapi/component.rb', line 47

def can_belong_to?(model)
  self.class.parent === model
end

#keyObject



39
40
41
# File 'lib/dnapi/component.rb', line 39

def key
  self::class.key_id
end

#to_hashObject



43
44
45
# File 'lib/dnapi/component.rb', line 43

def to_hash
  super.merge('key' => key)
end