Module: Itamae::Resource

Defined in:
lib/itamae/resource.rb,
lib/itamae/resource/git.rb,
lib/itamae/resource/base.rb,
lib/itamae/resource/file.rb,
lib/itamae/resource/link.rb,
lib/itamae/resource/user.rb,
lib/itamae/resource/group.rb,
lib/itamae/resource/execute.rb,
lib/itamae/resource/package.rb,
lib/itamae/resource/service.rb,
lib/itamae/resource/template.rb,
lib/itamae/resource/directory.rb,
lib/itamae/resource/gem_package.rb,
lib/itamae/resource/remote_file.rb,
lib/itamae/resource/local_ruby_block.rb,
lib/itamae/resource/remote_directory.rb

Defined Under Namespace

Classes: Base, Directory, Execute, File, GemPackage, Git, Group, Link, LocalRubyBlock, Package, RemoteDirectory, RemoteFile, Service, Template, User

Constant Summary collapse

Error =
Class.new(StandardError)
AttributeMissingError =
Class.new(StandardError)
InvalidTypeError =
Class.new(StandardError)
ParseError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.get_resource_class(method) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/itamae/resource.rb', line 38

def get_resource_class(method)
  begin
    const_get(get_resource_class_name(method))
  rescue NameError => e
    const_get(get_resource_plugin_class_name(method))
  end
end

.get_resource_class_name(method) ⇒ Object


26
27
28
# File 'lib/itamae/resource.rb', line 26

def get_resource_class_name(method)
  to_camel_case(method.to_s)
end

.get_resource_plugin_class_name(method) ⇒ Object


30
31
32
# File 'lib/itamae/resource.rb', line 30

def get_resource_plugin_class_name(method)
  '::Itamae::Plugin::Resource::' + to_camel_case(method.to_s)
end

.parse_description(desc) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/itamae/resource.rb', line 46

def parse_description(desc)
  if /\A([^\[]+)\[([^\]]+)\]\z/ =~ desc
    [$1, $2]
  else
    raise ParseError, "'#{desc}' doesn't represent a resource."
  end
end

.to_camel_case(str) ⇒ Object


34
35
36
# File 'lib/itamae/resource.rb', line 34

def to_camel_case(str)
  str.split('_').map {|part| part.capitalize}.join
end