Module: ArcWeld::Resource::ClassMethods

Defined in:
lib/arc_weld/resource.rb

Instance Method Summary collapse

Instance Method Details

#class_idObject



113
114
115
# File 'lib/arc_weld/resource.rb', line 113

def class_id
  self.class_variable_get :@@CLASS_ID
end

#class_propertiesObject



121
122
123
# File 'lib/arc_weld/resource.rb', line 121

def class_properties
  self.class_variable_get :@@RESOURCE_PROPERTIES
end

#class_rootObject



117
118
119
# File 'lib/arc_weld/resource.rb', line 117

def class_root
  self.class_variable_get :@@RESOURCE_ROOT
end

#register_property(sym) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/arc_weld/resource.rb', line 147

def register_property(sym)
  #puts format('registering property %s on %s', sym.to_s, self.name)
  unless class_properties.include?(sym)
    class_properties.push(sym)
    self.class_eval "attr_accessor :#{sym}"
  end
end

#resource_class_id(num) ⇒ Object



133
134
135
136
137
138
# File 'lib/arc_weld/resource.rb', line 133

def resource_class_id(num)
  fail ArgumentError, 'class id must be Integer' unless num.is_a?(Integer)
  #puts format('setting class id %d on %s', num, self.name)
  self.class_eval "@@CLASS_ID = #{num}"
  num
end

#resource_property(*syms) ⇒ Object



140
141
142
143
144
145
# File 'lib/arc_weld/resource.rb', line 140

def resource_property(*syms)
  syms.each do |sym|
    #puts format('defining resource property %s on %s', sym.to_s, self.name)
    register_property(sym)
  end
end

#resource_root(str) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/arc_weld/resource.rb', line 125

def resource_root(str)
  fail ArgumentError, 'resource root must be string' unless str.is_a?(String)
  #puts format('setting resource_root %s on %s', str, self.name)
  norm_str = (str.gsub(%r{\A/?},'').gsub(%r{/?\z},'').split(' ').map &:capitalize).join(' ')
  self.class_eval "@@RESOURCE_ROOT = \"/#{norm_str}/\""
  norm_str
end

#resource_typeObject



100
101
102
# File 'lib/arc_weld/resource.rb', line 100

def resource_type
  name.split('::')[-1]
end

#toplevelObject



105
106
107
108
109
110
111
# File 'lib/arc_weld/resource.rb', line 105

def toplevel
  @top ||= ArcWeld::Reference.new(
    type: 'Group',
    id:   format('01000100010001%03d', class_id),
    uri:  class_root
  )
end