Class: Bourdain::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/bourdain/resources.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Resource

Returns a new instance of Resource.



38
39
40
41
42
# File 'lib/bourdain/resources.rb', line 38

def initialize argv
  @status = 0
  @spec   = Bourdain::Helpers::UsageParser.parse(self.class.raw_usage)
  @opts   = trollop_with_spec(self.class.resource_type, argv, @spec)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/bourdain/resources.rb', line 6

def opts
  @opts
end

#raw_usageObject (readonly)

Returns the value of attribute raw_usage.



6
7
8
# File 'lib/bourdain/resources.rb', line 6

def raw_usage
  @raw_usage
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



6
7
8
# File 'lib/bourdain/resources.rb', line 6

def resource_name
  @resource_name
end

#specObject (readonly)

Returns the value of attribute spec.



6
7
8
# File 'lib/bourdain/resources.rb', line 6

def spec
  @spec
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/bourdain/resources.rb', line 6

def status
  @status
end

Class Method Details

.log=(log) ⇒ Object



8
# File 'lib/bourdain/resources.rb', line 8

def self.log= log ; @@log = log end

.raw_usageObject



12
# File 'lib/bourdain/resources.rb', line 12

def self.raw_usage ; raise 'not implemented' end

.resource_nameObject



10
# File 'lib/bourdain/resources.rb', line 10

def self.resource_name ; raise 'not implemented' end

.usage(type, raw_usage) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bourdain/resources.rb', line 14

def self.usage type, raw_usage
  type = type.to_s

  metaclass = class << self ; self ; end

  metaclass.send(:define_method, 'raw_usage') do
    raw_usage.gsub(/^ +/, '')
  end

  metaclass.send(:define_method, 'resource_name') do
    raw_usage.lines.to_a[1].split(' ').first
  end

  metaclass.send(:define_method, 'resource_type') do
    type
  end

  metaclass.send(:define_method, 'spec') do
    self.spec ||= Bourdain::Helpers::UsageParser.parse(self.class.raw_usage)
  end

  Bourdain::Registry.register(type, self)
end