Permalink
Browse files

module_eval for outlaw

  • Loading branch information...
bglusman
bglusman committed Jan 27, 2012
1 parent d2e1c87 commit dbfb3d13609e457ae2fc93fa8d942548f565ca49
Showing with 14 additions and 10 deletions.
  1. +4 −3 bin/outlaw
  2. +8 −5 lib/outlaw.rb
  3. +2 −2 lib/outlaw/law_dsl.rb
View
@@ -2,9 +2,9 @@
require "outlaw"
if File.exists?(Dir.pwd + '/.outlawed')
- load Dir.pwd + "/.outlawed"
+ File.open(Dir.pwd + "/.outlawed") {|f| Outlaw.module_eval(f.read)}
elsif File.exists?(Dir.home + '/.outlawed')
- load Dir.home + '/.outlawed'
+ File.open(Dir.home + '/.outlawed') {|f| Outlaw.module_eval(f.read)}
else
puts "
***NOTICE:***
@@ -14,7 +14,8 @@ else
at pwd first for ./outlawed and then at ~/.outlawed and defaults to example
if neither is found\n\n"
- load File.dirname(File.dirname(`gem which outlaw`.chop)) + '/examples/.outlawed.example'
+ File.open(File.dirname(File.dirname(`gem which outlaw`.chop)) +
+ '/examples/.outlawed.example') {|f| Outlaw.module_eval(f.read)}
end
puts Outlaw.enforce(ARGV[0] ? ARGV[0] : ".")
View
@@ -3,18 +3,21 @@
require_relative 'outlaw/enforcement'
require_relative 'outlaw/rule'
-def outlaw(restriction, message)
- law = Outlaw::LawDSL.parse(restriction, message)
- Outlaw::Enforcement.add(law)
-end
+
module Outlaw
+ def self.outlaw(restriction, message)
+ law = Outlaw::LawDSL.parse(restriction, message)
+ Outlaw::Enforcement.add(law)
+ end
+
def self.enforce(dir=".")
Outlaw::Enforcement.process_directory(dir)
end
PARAM_TYPES = [:on_const, :on_ident, :on_ivar, :on_cvar]
IGNORE_TYPES = [:on_sp, :on_nl, :on_ignored_nl, :on_rparen, :on_lparen]
- SPECIAL_CASES = [:disjoint_code_seperator] #need to work on naming here
+ #these come from ripper's Lexer
+ SPECIAL_CASES = [:disjoint_code_seperator, :whitespace_sensitive] #need to work on naming here
CORE_CLASSES_FILE = File.expand_path("../../data/core_classes.txt", __FILE__)
CORE_CLASS = File.readlines(CORE_CLASSES_FILE).map &:chomp
end
View
@@ -6,8 +6,8 @@ def parse(restriction, message="")
parsed_restriction = []
tokens.each do |token|
case
- when special_case?(token)
- next #TODO - handle AST branches/disjoint code/meta-symbols to be defined
+ when special_case?(token) # notional plan for handling flexibly
+ parsed_restriction << string_to_sym(token).to_proc
when multipart?(token) #this handles multi-token literals, Const.new etc
parsed_restriction += Ripper.lex(token)
.reduce([]){|array, tkn|

0 comments on commit dbfb3d1

Please sign in to comment.