Method: PgGraph::Reflection#initialize
- Defined in:
- lib/pg_graph/reflector.rb
#initialize(match, this, that, multi = nil, pluralize = nil, default_reflection = false) ⇒ Reflection
this and that are template strings, nil, or false
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pg_graph/reflector.rb', line 56 def initialize(match, this, that, multi = nil, pluralize = nil, default_reflection = false) constrain match, Regexp, String constrain this, String, NilClass constrain that, String, FalseClass, NilClass constrain multi, true, false, nil constrain pluralize, TrueClass, FalseClass, NilClass constrain default_reflection, TrueClass, FalseClass, NilClass @match = match.is_a?(Regexp) ? match.source : match if @match =~ /^\/(.*)\/$/ re = $1 @re = Regexp.new("^(?:\\w+\\.)*#{re}$") @components = re.scan(/(?<!\\)\\(?:\\\\)*\./).count + 1 else @re = Regexp.new("^(?:\\w+\\.)*#{@match}$") @components = @match.count(".") + 1 end (1..4).include?(@components) or raise "Illegal number of name components: #{@match}" @this = this @that = that @multi = multi @pluralize = pluralize @default_reflection = default_reflection || false end |