module DirModel::Import

Attributes

context[R]
foreign_value[R]
index[R]
load_state[R]
previous[R]
source_path[R]

Public Class Methods

new(path, options={}) click to toggle source
Calls superclass method
# File lib/dir_model/import.rb, line 7
def initialize(path, options={})
  super # set parent
  @source_path, @context = path, OpenStruct.new(options[:context])
  @index, @previous      = options[:index], options[:previous].try(:dup)
  @load_state            = :ghost
  @foreign_value         = options[:foreign_value]
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/dir_model/import.rb, line 20
def method_missing(name, *args, &block)
  load
  @_match[name]
rescue
  super
end
skip?() click to toggle source
# File lib/dir_model/import.rb, line 15
def skip?
  load
  !@_match
end

Private Instance Methods

find_match() click to toggle source
# File lib/dir_model/import.rb, line 88
def find_match
  @_match = (source_path||'').match(get_regexp)
end
get_regexp() click to toggle source
# File lib/dir_model/import.rb, line 92
def get_regexp
  args = []
  args << foreign_value if foreign_value
  instance_exec(*args, &self.class.options[:regex])
end
load()
Alias for: match?
match?() click to toggle source
# File lib/dir_model/import.rb, line 82
def match?
  return if load_state == :loaded
  @_match = find_match.tap { @load_state = :loaded }
end
Also aliased as: load