Class: Knish::ExistingModels

Inherits:
Struct
  • Object
show all
Defined in:
lib/knish/existing_models.rb

Defined Under Namespace

Classes: Data

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



2
3
4
# File 'lib/knish/existing_models.rb', line 2

def path
  @path
end

Instance Method Details

#dataObject



15
16
17
18
19
# File 'lib/knish/existing_models.rb', line 15

def data
  paths.map { |path|
    Data.new(id(path), path) if id(path)
  }.compact
end

#id(path) ⇒ Object



21
22
23
24
# File 'lib/knish/existing_models.rb', line 21

def id(path)
  last = path.split('/').last
  last && last.to_i
end

#idsObject



7
8
9
# File 'lib/knish/existing_models.rb', line 7

def ids
  paths.map{|path| id(path) }.compact
end

#next_idObject



3
4
5
# File 'lib/knish/existing_models.rb', line 3

def next_id
  (ids.max || 0) + 1
end

#pathsObject



11
12
13
# File 'lib/knish/existing_models.rb', line 11

def paths
  Dir.glob("#{path}/*")
end