Sha256: 1368b1921ac023689d2b7030baa20d9386e5221a4d1722c117df174be5743a6d

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

module Puffer
  module Controller
    module Config

      def self.included base
        base.class_eval do
          extend ClassMethods
          include InstanceMethods

          puffer_class_attribute :group, :default
          puffer_class_attribute :model
          puffer_class_attribute :destroy, true

          helper_method :configuration
        end
      end

      module InstanceMethods

        def configuration
          @configuration ||= Config.new(self.class)
        end

      end

      module ClassMethods

        def puffer_class_attribute name, default = nil
          class_attribute "_puffer_attribute_#{name}"
          send "_puffer_attribute_#{name}=", default
        end

        def configure &block
          block.bind(Config.new(self)).call
        end

        def configuration
          @configuration ||= Config.new(self)
        end

      end

      class Config

        attr_accessor :controller

        def initialize controller
          @controller = controller
        end

        def method_missing method, *args, &block
          method_name = "_puffer_attribute_#{method}"
          if args.present? && controller.respond_to?("#{method_name}=")
            controller.send "#{method_name}=", args.first
          elsif controller.respond_to?(method_name)
            controller.send method_name
          end
        end

      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
puffer-0.0.15 lib/puffer/controller/config.rb
puffer-0.0.14 lib/puffer/controller/config.rb
puffer-0.0.13 lib/puffer/controller/config.rb
puffer-0.0.12 lib/puffer/controller/config.rb
puffer-0.0.11 lib/puffer/controller/config.rb
puffer-0.0.10 lib/puffer/controller/config.rb
puffer-0.0.9 lib/puffer/controller/config.rb
puffer-0.0.8 lib/puffer/controller/config.rb
puffer-0.0.7 lib/puffer/controller/config.rb