Class: FaaStRuby::Local::ListenerEvent

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/faastruby/local/listeners/listener.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#debug, puts, #puts

Constructor Details

#initialize(type:, full_path:, listened_directory:) ⇒ ListenerEvent

Returns a new instance of ListenerEvent.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/faastruby/local/listeners/listener.rb', line 59

def initialize(type:, full_path:, listened_directory:)
  debug "initialize(type: #{type.inspect}, full_path: #{full_path.inspect}, listened_directory: #{listened_directory.inspect})"
  @listened_directory = listened_directory
  @full_path = full_path
  @relative_path = relative_path_for(@full_path.dup)
  @relative_path_dirname = File.dirname(@relative_path)
  @filename = File.basename(@full_path)
  @dirname = File.dirname(@full_path)
  @type = type

  debug "EVENT: #{@type}"
  debug "EVENT: #{@full_path}"
end

Instance Attribute Details

#dirnameObject

Returns the value of attribute dirname.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def dirname
  @dirname
end

#filenameObject

Returns the value of attribute filename.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def filename
  @filename
end

#full_pathObject

Returns the value of attribute full_path.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def full_path
  @full_path
end

#listened_directoryObject

Returns the value of attribute listened_directory.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def listened_directory
  @listened_directory
end

#relative_pathObject

Returns the value of attribute relative_path.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def relative_path
  @relative_path
end

#relative_path_dirnameObject

Returns the value of attribute relative_path_dirname.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def relative_path_dirname
  @relative_path_dirname
end

#typeObject

Returns the value of attribute type.



58
59
60
# File 'lib/faastruby/local/listeners/listener.rb', line 58

def type
  @type
end

Instance Method Details

#added?Boolean

def file_was_just_added?

debug __method__
Time.now.to_i - File.ctime(@full_path).to_i <= 1

end

Returns:

  • (Boolean)


119
120
121
122
# File 'lib/faastruby/local/listeners/listener.rb', line 119

def added?
  debug __method__
  @type == :added
end

#file_is_a_function_config?Boolean

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/faastruby/local/listeners/listener.rb', line 105

def file_is_a_function_config?
  debug __method__
  filename == 'faastruby.yml'
end

#file_is_a_gemfile?Boolean

Returns:

  • (Boolean)


90
91
92
93
# File 'lib/faastruby/local/listeners/listener.rb', line 90

def file_is_a_gemfile?
  debug __method__
  filename == 'Gemfile'
end

#file_is_a_gemfile_lock?Boolean

Returns:

  • (Boolean)


95
96
97
98
# File 'lib/faastruby/local/listeners/listener.rb', line 95

def file_is_a_gemfile_lock?
  debug __method__
  filename == 'Gemfile.lock'
end

#file_is_a_handler?Boolean

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/faastruby/local/listeners/listener.rb', line 100

def file_is_a_handler?
  debug __method__
  filename.match(/^handler\.(rb|cr)$/)
end

#file_is_opal_main?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/faastruby/local/listeners/listener.rb', line 110

def file_is_opal_main?
  filename == 'main.rb'
end

#function_created?Boolean

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/faastruby/local/listeners/listener.rb', line 85

def function_created?
  debug __method__
  added? && filename.match(/^handler\.(rb|cr)$/)
end

#modified?Boolean

Returns:

  • (Boolean)


124
125
126
127
# File 'lib/faastruby/local/listeners/listener.rb', line 124

def modified?
  debug __method__
  @type == :modified
end

#relative_path_for(full_path) ⇒ Object



134
135
136
137
138
# File 'lib/faastruby/local/listeners/listener.rb', line 134

def relative_path_for(full_path)
  debug "relative_path_for(#{full_path.inspect})"
  full_path.slice!("#{@listened_directory}/")
  full_path
end

#removed?Boolean

Returns:

  • (Boolean)


129
130
131
132
# File 'lib/faastruby/local/listeners/listener.rb', line 129

def removed?
  debug __method__
  @type == :removed
end

#to_hObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/faastruby/local/listeners/listener.rb', line 73

def to_h
  {
    listened_directory: @listened_directory,
    full_path: @full_path,
    relative_path: @relative_path,
    relative_path_dirname: @relative_path_dirname,
    filename: @filename,
    dirname: @dirname,
    type: @type
  }
end