Sha256: 0d538368511db18700c15c757ca7bfb60e77ea1905011c5bc812876005f5ae1e

Contents?: true

Size: 748 Bytes

Versions: 6

Compression:

Stored size: 748 Bytes

Contents

module Fierce
  module DelegateGenerator
    class Controller
      attr_reader :controller

      def initialize(controller)
        @controller = controller
      end

      def generate
        delegate_class.new(*ivars)
      end

      def delegate_class
        Struct.new(*accessor_names)
      end

      def accessor_names
        ivar_names.map {|name| name.to_s.gsub('@', '').to_sym }
      end

      def ivar_names
        controller.instance_variables - 
          controller.protected_instance_variables -
          excluded_ivars
      end

      def excluded_ivars
        [:@template]
      end

      def ivars
        ivar_names.map { |name|
          controller.instance_variable_get(name)
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fierce-0.2.0 lib/fierce/delegate_generator/controller.rb
fierce-0.1.4 lib/fierce/delegate_generator/controller.rb
fierce-0.1.3 lib/fierce/delegate_generator/controller.rb
fierce-0.1.2 lib/fierce/delegate_generator/controller.rb
fierce-0.1.1 lib/fierce/delegate_generator/controller.rb
fierce-0.1.0 lib/fierce/delegate_generator/controller.rb