Sha256: 22368c81c1809dfb937ba0a5f54ee8397c323009e98d4bd98c149188c5826f74

Contents?: true

Size: 1.45 KB

Versions: 11

Compression:

Stored size: 1.45 KB

Contents

require 'itamae'
require 'itamae/resource/base'
require 'itamae/resource/file'
require 'itamae/resource/package'
require 'itamae/resource/remote_directory'
require 'itamae/resource/remote_file'
require 'itamae/resource/directory'
require 'itamae/resource/template'
require 'itamae/resource/execute'
require 'itamae/resource/service'
require 'itamae/resource/link'
require 'itamae/resource/local_ruby_block'
require 'itamae/resource/git'
require 'itamae/resource/user'
require 'itamae/resource/group'

module Itamae
  module Resource
    Error = Class.new(StandardError)
    AttributeMissingError = Class.new(StandardError)
    InvalidTypeError = Class.new(StandardError)
    ParseError = Class.new(StandardError)

    class << self
      def get_resource_class_name(method)
        to_camel_case(method.to_s)
      end

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

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

      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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
itamae-1.1.14 lib/itamae/resource.rb
itamae-1.1.13 lib/itamae/resource.rb
itamae-1.1.12 lib/itamae/resource.rb
itamae-1.1.11 lib/itamae/resource.rb
itamae-1.1.10 lib/itamae/resource.rb
itamae-1.1.9 lib/itamae/resource.rb
itamae-1.1.8 lib/itamae/resource.rb
itamae-1.1.7 lib/itamae/resource.rb
itamae-1.1.5 lib/itamae/resource.rb
itamae-1.1.4 lib/itamae/resource.rb
itamae-1.1.3 lib/itamae/resource.rb