Class: Bourdain::Resource
- Inherits:
-
Object
- Object
- Bourdain::Resource
- Defined in:
- lib/bourdain/resources.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#raw_usage ⇒ Object
readonly
Returns the value of attribute raw_usage.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Resource
constructor
A new instance of Resource.
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
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
6 7 8 |
# File 'lib/bourdain/resources.rb', line 6 def opts @opts end |
#raw_usage ⇒ Object (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_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
6 7 8 |
# File 'lib/bourdain/resources.rb', line 6 def resource_name @resource_name end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
6 7 8 |
# File 'lib/bourdain/resources.rb', line 6 def spec @spec end |
#status ⇒ Object (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_usage ⇒ Object
12 |
# File 'lib/bourdain/resources.rb', line 12 def self.raw_usage ; raise 'not implemented' end |
.resource_name ⇒ Object
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 = class << self ; self ; end .send(:define_method, 'raw_usage') do raw_usage.gsub(/^ +/, '') end .send(:define_method, 'resource_name') do raw_usage.lines.to_a[1].split(' ').first end .send(:define_method, 'resource_type') do type end .send(:define_method, 'spec') do self.spec ||= Bourdain::Helpers::UsageParser.parse(self.class.raw_usage) end Bourdain::Registry.register(type, self) end |