Class: Classifile::State

Inherits:
Object
  • Object
show all
Includes:
AssertChecker, ExtensionChecker, NameChecker
Defined in:
lib/classifile/state.rb

Overview

Class that manages the current state. The DSL code will be executed on an instance of this class A State is created for each dir and group.

Instance Attribute Summary collapse

Attributes included from NameChecker

#name

Attributes included from ExtensionChecker

#extname

Instance Method Summary collapse

Methods included from NameChecker

#end_with?, #include?

Methods included from ExtensionChecker

#image?, #movie?, #sound?

Methods included from AssertChecker

#method_missing, #respond_to_missing?

Constructor Details

#initialize(file) ⇒ State

Returns a new instance of State.



23
24
25
26
27
28
29
30
# File 'lib/classifile/state.rb', line 23

def initialize(file)
  @file = file
  @empty = false
  @extname = @file.extname
  @name = @file.basename
  @gotcha = nil
  super()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Classifile::AssertChecker

Instance Attribute Details

#additional_filenameObject

Returns the value of attribute additional_filename.



14
15
16
# File 'lib/classifile/state.rb', line 14

def additional_filename
  @additional_filename
end

#after_save_symsObject

Returns the value of attribute after_save_syms.



14
15
16
# File 'lib/classifile/state.rb', line 14

def after_save_syms
  @after_save_syms
end

#emptyObject Also known as: empty?

Returns the value of attribute empty.



14
15
16
# File 'lib/classifile/state.rb', line 14

def empty
  @empty
end

#fileObject

Returns the value of attribute file.



14
15
16
# File 'lib/classifile/state.rb', line 14

def file
  @file
end

#gotchaObject (readonly)

Returns the value of attribute gotcha.



20
21
22
# File 'lib/classifile/state.rb', line 20

def gotcha
  @gotcha
end

#save_nameObject

Returns the value of attribute save_name.



14
15
16
# File 'lib/classifile/state.rb', line 14

def save_name
  @save_name
end

#to_pathObject

Returns the value of attribute to_path.



14
15
16
# File 'lib/classifile/state.rb', line 14

def to_path
  @to_path
end

Instance Method Details

#after_save(method_name) ⇒ Object



66
67
68
# File 'lib/classifile/state.rb', line 66

def after_save(method_name)
  @after_save_syms << method_name
end

#del(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/classifile/state.rb', line 52

def del(&block)
  return if @gotcha

  child = make_child ""
  child_run!(child, block) do
    @gotcha = RemoveFile.new(File.expand_path(@file.full_path))
    sets_after_save_proc(child)
  end
end

#dir(dir_name, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/classifile/state.rb', line 32

def dir(dir_name, &block)
  return if @gotcha

  child = make_child dir_name
  child_run!(child, block) do
    @gotcha = MoveFile.new(File.expand_path(@file.full_path),
                           File.expand_path(File.join(child.to_path, child.save_name)))
    sets_after_save_proc(child)
  end
end

#empty_dir!Object



62
63
64
# File 'lib/classifile/state.rb', line 62

def empty_dir!
  @empty = true
end

#group(_group_name = "", &block) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/classifile/state.rb', line 43

def group(_group_name = "", &block)
  return if @gotcha

  child = make_child ""
  child_run!(child, block) do
    # Ignored
  end
end