Sha256: bfc9330c48a121fd366330f49396e7628497982a5224ac37325c5e9d2e150292

Contents?: true

Size: 1.07 KB

Versions: 57

Compression:

Stored size: 1.07 KB

Contents

module Pfm
  module Generator
    # This is here to hold attr_accessor data for Generator context variables
    class Context
      def self.add_attr(name)
        @attributes ||= []

        unless @attributes.include?(name)
          @attributes << name
          attr_accessor(name)
        end
      end

      def self.reset
        return if @attributes.nil?

        @attributes.each do |attr|
          remove_method(attr)
        end

        @attributes = nil
      end
    end

    def self.reset
      @context = nil
    end

    def self.context
      @context ||= Context.new
    end

    def self.add_attr_to_context(name, value = nil)
      sym_name = name.to_sym
      Pfm::Generator::Context.add_attr(sym_name)
      Pfm::Generator::TemplateHelper.delegate_to_app_context(sym_name)
      context.public_send("#{sym_name}=", value)
    end

    module TemplateHelper
      def self.delegate_to_app_context(name)
        define_method(name) do
          Pfm::Generator.context.public_send(name)
        end
      end

      def year
        Time.now.year
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 2 rubygems

Version Path
iapi-idlc-sdk-pfm-1.0.13 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.12 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.11 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.10 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.9 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.8 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.7 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.6 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.5 lib/iapi-idlc-sdk-pfm/generator.rb
iapi-idlc-sdk-pfm-1.0.4 lib/iapi-idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.2.2 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.2.1 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.2.0 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.1.4 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.1.3 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.1.2 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.1.1 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.1.0 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.0.21 lib/idlc-sdk-pfm/generator.rb
idlc-sdk-pfm-1.0.20 lib/idlc-sdk-pfm/generator.rb