Class: Resource
- Inherits:
-
Object
- Object
- Resource
- Defined in:
- lib/resource.rb
Defined Under Namespace
Classes: ResourceError
Instance Attribute Summary collapse
-
#expected_properties ⇒ Object
readonly
Returns the value of attribute expected_properties.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#puppet_resource ⇒ Object
readonly
Returns the value of attribute puppet_resource.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #check_properties ⇒ Object
-
#initialize(title, properties) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(title, properties) ⇒ Resource
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/resource.rb', line 18 def initialize(title, properties) if title.to_s =~ /^([A-Z].+)\[(.+)\]$/ @type = $1.to_s.downcase.to_sym @name =$2.to_s.gsub(/'|"/, '') else raise ResourceError, "invalid resource title - #{title}" end @title = title @expected_properties = properties @compare_fn = lambda do |name, expected, actual| if name == :ensure if expected == 'present' return actual != :absent end if expected == 'absent' expected = expected.to_sym # user can express it as 'absent' or :absent end end expected == actual end create_resource end |
Instance Attribute Details
#expected_properties ⇒ Object (readonly)
Returns the value of attribute expected_properties.
15 16 17 |
# File 'lib/resource.rb', line 15 def expected_properties @expected_properties end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/resource.rb', line 14 def name @name end |
#puppet_resource ⇒ Object (readonly)
Returns the value of attribute puppet_resource.
16 17 18 |
# File 'lib/resource.rb', line 16 def puppet_resource @puppet_resource end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
12 13 14 |
# File 'lib/resource.rb', line 12 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/resource.rb', line 13 def type @type end |
Instance Method Details
#check_properties ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/resource.rb', line 46 def check_properties result = { :success => true, :title => @title, :properties => [] } @expected_properties.each do |property, value| status = @compare_fn.call(property, value, @puppet_resource[property]) result[:success] = false unless status result[:properties] << { :name => property, :expected => value, :actual => @puppet_resource[property].to_s, :success => status } end result end |