Sha256: ed485aa4382294787e0301197844b73089a7eceacc83a5eb924d4a05e437ed37

Contents?: true

Size: 924 Bytes

Versions: 18

Compression:

Stored size: 924 Bytes

Contents

require "active_support/core_ext/string"

# Encapsulates helper methods and instance variables to be rendered in the ERB
# templates.
module AwsEc2::Template
  class Context
    include AwsEc2::Template::Helper

    def initialize(options={})
      @options = options
      load_custom_helpers
    end

  private
    # Load custom helper methods from project
    def load_custom_helpers
      Dir.glob("#{AwsEc2.root}/app/helpers/**/*_helper.rb").each do |path|
        filename = path.sub(%r{.*/},'').sub('.rb','')
        module_name = filename.classify

        # Prepend a period so require works AWS_EC2_ROOT is set to a relative path
        # without a period.
        #
        # Example: AWS_EC2_ROOT=tmp/project
        first_char = path[0..0]
        path = "./#{path}" unless %w[. /].include?(first_char)
        require path
        self.class.send :include, module_name.constantize
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aws-ec2-1.4.9 lib/aws_ec2/template/context.rb
aws-ec2-1.4.8 lib/aws_ec2/template/context.rb
aws-ec2-1.4.7 lib/aws_ec2/template/context.rb
aws-ec2-1.4.6 lib/aws_ec2/template/context.rb
aws-ec2-1.4.5 lib/aws_ec2/template/context.rb
aws-ec2-1.4.4 lib/aws_ec2/template/context.rb
aws-ec2-1.4.3 lib/aws_ec2/template/context.rb
aws-ec2-1.4.2 lib/aws_ec2/template/context.rb
aws-ec2-1.4.1 lib/aws_ec2/template/context.rb
aws-ec2-1.4.0 lib/aws_ec2/template/context.rb
aws-ec2-1.3.2 lib/aws_ec2/template/context.rb
aws-ec2-1.3.1 lib/aws_ec2/template/context.rb
aws-ec2-1.3.0 lib/aws_ec2/template/context.rb
aws-ec2-1.2.2 lib/aws_ec2/template/context.rb
aws-ec2-1.2.1 lib/aws_ec2/template/context.rb
aws-ec2-1.2.0 lib/aws_ec2/template/context.rb
aws-ec2-1.1.0 lib/aws_ec2/template/context.rb
aws-ec2-1.0.0 lib/aws_ec2/template/context.rb