Sha256: 40704334fd3bc7309c077aa7c22cfd9eea79091d8372145cca5f35fdd0f5883e

Contents?: true

Size: 725 Bytes

Versions: 3

Compression:

Stored size: 725 Bytes

Contents

module Happy
  module Extras
    class Scriptable < Happy::Controller
      def route
        run_script 'permissions.rb'
        run_script 'route.rb'
      end

      def run_script(name)
        instance_exec &get_proc_for_script(name)
      end

      def get_proc_for_script(name)
        if reload_script?(name)
          procs[name] = eval "lambda { %s }" % load_script(name)
        end
        procs[name]
      end

      def reload_script?(name)
        !procs[name] || Happy.env.development?
      end

      def load_script(name)
        file_name = File.expand_path(File.join(settings[:directory], name))
        File.read(file_name)
      end

      def procs
        @procs ||= {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
happy-0.1.0 lib/happy/extras/scriptable.rb
happy-0.1.0.pre28 lib/happy/extras/scriptable.rb
happy-0.1.0.pre27 lib/happy/extras/scriptable.rb