Permalink
Browse files

remove trailing whitespace

  • Loading branch information...
companygardener committed Oct 12, 2011
1 parent 89611fd commit 0ba696681b2d9a6403278f7af86567015845ff07
View
@@ -14,13 +14,13 @@ class << self
def config
@config ||= Config.new
end
-
+
def configure(&block)
config.configure(&block)
end
-
+
def parser(options = {})
@parser ||= Parser.new({:config => config}.merge(options))
end
end
-end
+end
View
@@ -70,7 +70,7 @@ def find_first_model(klass, conditions)
def find_all_models(klass, conditions)
klass.const_get(:PickleAdapter).find_all_models(klass, conditions)
end
-
+
def create_model(klass, attributes)
klass.const_get(:PickleAdapter).create_model(klass, attributes)
end
@@ -48,7 +48,7 @@ def self.find_first_model(klass, conditions)
def self.find_all_models(klass, conditions)
klass.find(:all, :conditions => conditions)
end
-
+
# Create a model using attributes
def self.create_model(klass, attributes)
klass.create!(attributes)
@@ -33,7 +33,7 @@ def self.find_first_model(klass, conditions)
def self.find_all_models(klass, conditions)
klass.all(conditions)
end
-
+
# Create a model using attributes
def self.create_model(klass, attributes)
klass.create(attributes)
View
@@ -1,29 +1,29 @@
module Pickle
class Config
attr_writer :adapters, :factories, :mappings, :predicates
-
+
def initialize(&block)
configure(&block) if block_given?
end
-
+
def configure(&block)
yield(self)
end
-
+
def adapters
@adapters ||= [:machinist, :factory_girl, :fabrication, :orm]
end
-
+
def adapter_classes
adapters.map {|a| a.is_a?(Class) ? a : "pickle/adapter/#{a}".classify.constantize}
end
-
+
def factories
@factories ||= adapter_classes.reverse.inject({}) do |factories, adapter|
factories.merge(adapter.factories.inject({}){|h, f| h.merge(f.name => f)})
end
end
-
+
def predicates
@predicates ||= Pickle::Adapter.model_classes.map do |k|
k.public_instance_methods.select {|m| m =~ /\?$/} + Pickle::Adapter.column_names(k)
@@ -32,11 +32,11 @@ def predicates
class Mapping < Struct.new(:search, :replacement)
end
-
+
def mappings
@mappings ||= []
end
-
+
# Usage: map 'me', 'myself', 'I', :to => 'user: "me"'
def map(*args)
options = args.extract_options!
@@ -9,10 +9,10 @@ def match_email
def capture_email
"(#{match_email})"
end
-
+
def capture_index_in_email
"(?:#{match_prefix}?(?:#{capture_index} )?email)"
end
end
end
-end
+end
View
@@ -3,13 +3,13 @@
module Pickle
class Parser
include Matchers
-
+
attr_reader :config
-
+
def initialize(options = {})
@config = options[:config] || raise(ArgumentError, "Parser.new requires a :config")
end
-
+
# given a string like 'foo: "bar", bar: "baz"' returns {"foo" => "bar", "bar" => "baz"}
def parse_fields(fields)
if fields.blank?
@@ -19,10 +19,10 @@ def parse_fields(fields)
m.merge(parse_field(match[0]))
end
else
- raise ArgumentError, "The fields string is not in the correct format.\n\n'#{fields}' did not match: #{match_fields}"
+ raise ArgumentError, "The fields string is not in the correct format.\n\n'#{fields}' did not match: #{match_fields}"
end
end
-
+
# given a string like 'foo: expr' returns {key => value}
def parse_field(field)
if field =~ /^#{capture_key_and_value_in_field}$/
@@ -31,12 +31,12 @@ def parse_field(field)
raise ArgumentError, "The field argument is not in the correct format.\n\n'#{field}' did not match: #{match_field}"
end
end
-
+
# returns really underscored name
def canonical(str)
str.to_s.underscore.gsub(' ','_').gsub('/','_')
end
-
+
# return [factory_name, name or integer index]
def parse_model(model_name)
apply_mappings!(model_name)
@@ -46,7 +46,7 @@ def parse_model(model_name)
[canonical($1), canonical($2)]
end
end
-
+
def parse_index(index)
case index
when nil, '', 'last' then -1
@@ -62,4 +62,4 @@ def apply_mappings!(string)
end
end
end
-end
+end
@@ -4,19 +4,19 @@ module Matchers
def match_ordinal
'(?:\d+(?:st|nd|rd|th))'
end
-
+
def match_index
"(?:first|last|#{match_ordinal})"
end
-
+
def match_prefix
'(?:(?:a|an|another|the|that) )'
end
-
+
def match_quoted
'(?:\\\\"|[^\\"]|\\.)*'
end
-
+
def match_label
"(?::? \"#{match_quoted}\")"
end
@@ -28,60 +28,60 @@ def match_value
def match_field
"(?:\\w+: #{match_value})"
end
-
+
def match_fields
"(?:#{match_field}, )*#{match_field}"
end
-
+
def match_mapping
"(?:#{config.mappings.map(&:search).join('|')})"
end
-
+
def match_factory
"(?:#{config.factories.keys.map{|n| n.gsub('_','[_ ]')}.join('|')})"
end
-
+
def match_plural_factory
"(?:#{config.factories.keys.map{|n| n.pluralize.gsub('_','[_ ]')}.join('|')})"
end
-
+
def match_indexed_model
"(?:(?:#{match_index} )?#{match_factory})"
end
-
+
def match_labeled_model
"(?:#{match_factory}#{match_label})"
end
-
+
def match_model
"(?:#{match_mapping}|#{match_prefix}?(?:#{match_indexed_model}|#{match_labeled_model}))"
end
-
+
def match_predicate
"(?:#{config.predicates.map{|m| m.to_s.sub(/^has_/,'').sub(/\?$/,'').gsub('_','[_ ]')}.join('|')})"
end
-
+
# create capture analogues of match methods
instance_methods.select{|m| m =~ /^match_/}.each do |method|
- eval <<-end_eval
+ eval <<-end_eval
def #{method.to_s.sub('match_', 'capture_')} # def capture_field
"(" + #{method} + ")" # "(" + match_field + ")"
end # end
end_eval
end
-
+
# special capture methods
def capture_number_in_ordinal
'(?:(\d+)(?:st|nd|rd|th))'
end
-
+
def capture_name_in_label
"(?::? \"(#{match_quoted})\")"
end
-
+
def capture_key_and_value_in_field
"(?:(\\w+): #{capture_value})"
end
end
end
-end
+end
View
@@ -21,7 +21,7 @@ def path_to_pickle(*pickle_names)
pickle_path_for_resources_action_segment(resources, options[:action], options[:segment])
end or raise "Could not figure out a path for #{pickle_names.inspect} #{options.inspect}"
end
-
+
protected
def find_pickle_path_using_action_segment_combinations(resources, parts)
path = nil
@@ -32,7 +32,7 @@ def find_pickle_path_using_action_segment_combinations(resources, parts)
end
path
end
-
+
def pickle_path_for_resources_action_segment(resources, action, segment)
action.blank? or action = action.downcase.gsub(' ','_')
segment.blank? or segment = segment.downcase.gsub(' ','_')
@@ -42,4 +42,4 @@ def pickle_path_for_resources_action_segment(resources, action, segment)
send("#{parts.join('_')}_path", *models) rescue nil
end
end
-end
+end
Oops, something went wrong.

0 comments on commit 0ba6966

Please sign in to comment.