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/http_request.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, HttpRequest, 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

.autoload_plugin_resource(method) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/itamae/resource.rb', line 42

def autoload_plugin_resource(method)
  begin
    require "itamae/plugin/resource/#{method}"
    ::Itamae::Plugin::Resource.const_get(to_camel_case(method.to_s))
  rescue LoadError, NameError
    raise Error, "#{method} resource is missing."
  end
end

.define_resource(name, klass) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/itamae/resource.rb', line 51

def define_resource(name, klass)
  class_name = to_camel_case(name.to_s)
  if Resource.const_defined?(class_name)
    Itamae.logger.warn "Redefine class. (#{class_name})"
    return
  end

  Resource.const_set(class_name, klass)
end

.get_resource_class(method) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/itamae/resource.rb', line 30

def get_resource_class(method)
  begin
    self.const_get(to_camel_case(method.to_s))
  rescue NameError
    begin
      ::Itamae::Plugin::Resource.const_get(to_camel_case(method.to_s))
    rescue NameError
      autoload_plugin_resource(method)
    end
  end
end

.parse_description(desc) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/itamae/resource.rb', line 61

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



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

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