Class: Findable::Seed

Inherits:
Object
  • Object
show all
Defined in:
lib/findable/seed.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_path, seed_dir) ⇒ Seed

Returns a new instance of Seed.



23
24
25
26
# File 'lib/findable/seed.rb', line 23

def initialize(full_path, seed_dir)
  @_full_path = full_path
  @_seed_dir = seed_dir
end

Class Method Details

.pathname(path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/findable/seed.rb', line 14

def pathname(path)
  case path
  when Pathname then path
  when String then Pathname.new(path)
  else nil
  end
end

.target_files(seed_dir: nil, seed_files: nil) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
# File 'lib/findable/seed.rb', line 4

def target_files(seed_dir: nil, seed_files: nil)
  target_dir = pathname(seed_dir) || Findable.config.seed_dir
  raise ArgumentError unless target_dir
  Pathname.glob(target_dir.join("**", "*")).map {|full_path|
    new(full_path, target_dir)
  }.select {|seed|
    seed_files.present? ? seed_files.include?(seed.basename) : true
  }
end

Instance Method Details

#basenameObject



28
29
30
# File 'lib/findable/seed.rb', line 28

def basename
  @_basename ||= @_full_path.basename(".*").to_s
end

#bootstrap!Object



36
37
38
39
40
41
# File 'lib/findable/seed.rb', line 36

def bootstrap!
  model.query.lock do
    model.delete_all
    model.query.import YAML.load_file(@_full_path).values
  end
end

#modelObject



32
33
34
# File 'lib/findable/seed.rb', line 32

def model
  @_model ||= from_seed_dir(without_ext(@_full_path)).to_s.classify.constantize
end