Class: HaveAPI::Fs::Components::ResourceInstanceDir

Inherits:
ResourceDir show all
Defined in:
lib/haveapi/fs/components/resource_instance_dir.rb

Constant Summary

Constants included from Help

Help::SEARCH_PATH

Instance Attribute Summary

Attributes inherited from ResourceDir

#resource

Attributes inherited from HaveAPI::Fs::Component

#atime, #context, #ctime, #mtime

Instance Method Summary collapse

Methods inherited from ResourceDir

#delete, #initialize, #refresh

Methods inherited from Directory

#directory?

Methods included from Help

find!, included

Methods inherited from HaveAPI::Fs::Component

#abspath, #bound=, #bound?, children_reader, component, #directory?, #executable?, #file?, #find, inherited, #initialize, #invalid?, #invalidate, #parent, #path, #readable?, #reset, #times, #unsaved?, #use, #writable?

Constructor Details

This class inherits a constructor from HaveAPI::Fs::Components::ResourceDir

Instance Method Details

#attributesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 63

def attributes
  ret = []
  params = @resource.actions[:show].params

  @resource.attributes.each do |k, v|
    next if k == :_meta

    if params[k][:type] == 'Resource'
      ret << "#{k}_id"
      ret << k.to_s if v

    else
      ret << k.to_s
    end
  end

  ret
end

#contentsObject



16
17
18
19
20
21
22
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 16

def contents
  ret = super - %w(create.yml)
  ret.concat(attributes)
  ret.concat(%w(save edit.yml)) if @update
  ret << 'meta'
  ret
end

#replace_association(name, id) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 30

def replace_association(name, id)
  return unless children.has_key?(name)

  children[name].invalidate
  context.cache.drop_below(path)

  @resource.send("#{name}_id=", id)
  children[name] = [ResourceInstanceDir, @resource.send(name)]
end

#saveObject



24
25
26
27
28
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 24

def save
  ret = @update.exec
  self.mtime = Time.now
  ret
end

#setupObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 5

def setup
  super
 
  @show = use(:actions, :show)
  @update = use(:actions, :update)
  children[:save] = [SaveInstance, self, bound: true] if @update

  # Disable object listing from ResourceDir.contents
  @index = false
end

#subresourcesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 47

def subresources
  return @subresources if @subresources
  @subresources = []

  @resource.resources.each do |r_name, r|
    r.actions.each do |a_name, a|
      if a.url.index(":#{@resource._name}_id")
        @subresources << r_name
        break
      end
    end
  end

  @subresources
end

#titleObject



82
83
84
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 82

def title
  "#{@resource._name.to_s.capitalize} ##{@resource.id}"
end

#update_association(name) ⇒ Object



40
41
42
43
44
45
# File 'lib/haveapi/fs/components/resource_instance_dir.rb', line 40

def update_association(name)
  children[name].invalidate
  context.cache.drop_below(path)

  children[name] = [ResourceInstanceDir, @resource.send(name)]
end