Class: ImageVenue::Directory
- Inherits:
-
Object
- Object
- ImageVenue::Directory
- Defined in:
- lib/image_venue/directory.rb
Class Attribute Summary collapse
-
.debug ⇒ Object
Returns the value of attribute debug.
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .create_directory_key ⇒ Object
- .create_params(directory_name) ⇒ Object
- .create_uri ⇒ Object
- .debug? ⇒ Boolean
- .delete_directory_key ⇒ Object
- .delete_params(directory_name) ⇒ Object
- .delete_uri ⇒ Object
- .list(connection = nil) ⇒ Object
- .list_uri ⇒ Object
- .puts_debug(*args) ⇒ Object
- .select_directory_key ⇒ Object
- .select_params(directory_name) ⇒ Object
- .select_uri ⇒ Object
Instance Method Summary collapse
- #clear_cache ⇒ Object
- #debug? ⇒ Boolean
- #destroy(force = false, reload = false) ⇒ Object
- #files(reload = false) ⇒ Object
-
#initialize(connection, name, is_new = true) ⇒ Directory
constructor
A new instance of Directory.
- #is_new? ⇒ Boolean
- #puts_debug(*args) ⇒ Object
- #save(force = false, reload = false) ⇒ Object
- #select(reselect = false) ⇒ Object
Constructor Details
#initialize(connection, name, is_new = true) ⇒ Directory
Returns a new instance of Directory.
92 93 94 95 96 97 |
# File 'lib/image_venue/directory.rb', line 92 def initialize(connection, name, is_new=true) self.connection = connection self.name = name @is_new = is_new return nil end |
Class Attribute Details
.debug ⇒ Object
Returns the value of attribute debug.
4 5 6 |
# File 'lib/image_venue/directory.rb', line 4 def debug @debug end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
88 89 90 |
# File 'lib/image_venue/directory.rb', line 88 def connection @connection end |
#debug ⇒ Object
Returns the value of attribute debug.
89 90 91 |
# File 'lib/image_venue/directory.rb', line 89 def debug @debug end |
#name ⇒ Object
Returns the value of attribute name.
90 91 92 |
# File 'lib/image_venue/directory.rb', line 90 def name @name end |
Class Method Details
.create_directory_key ⇒ Object
35 36 37 |
# File 'lib/image_venue/directory.rb', line 35 def create_directory_key @create_directory_key ||= 'new_dir' end |
.create_params(directory_name) ⇒ Object
47 48 49 50 51 |
# File 'lib/image_venue/directory.rb', line 47 def create_params(directory_name) { self.create_directory_key => directory_name } end |
.create_uri ⇒ Object
31 32 33 |
# File 'lib/image_venue/directory.rb', line 31 def create_uri @create_uri ||= URI.parse(ImageVenue.base_url + '/create_dir.php') end |
.debug? ⇒ Boolean
6 7 8 |
# File 'lib/image_venue/directory.rb', line 6 def debug? (ImageVenue.debug? or self.debug) ? true : false end |
.delete_directory_key ⇒ Object
43 44 45 |
# File 'lib/image_venue/directory.rb', line 43 def delete_directory_key @delete_directory_key ||= 'delete_dir[]' end |
.delete_params(directory_name) ⇒ Object
53 54 55 56 57 |
# File 'lib/image_venue/directory.rb', line 53 def delete_params(directory_name) { self.delete_directory_key => directory_name } end |
.delete_uri ⇒ Object
39 40 41 |
# File 'lib/image_venue/directory.rb', line 39 def delete_uri @delete_uri ||= URI.parse(ImageVenue.base_url + '/process_del_dir.php') end |
.list(connection = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/image_venue/directory.rb', line 65 def list(connection=nil) self.puts_debug "Trying to fetch directories ..." request = Net::HTTP::Get.new(self.list_uri.path) request.header['cookie'] = [connection.] response = Net::HTTP.start(self.list_uri.host, self.list_uri.port) do |http| http.request(request) end if response.is_a?(Net::HTTPSuccess) directories = [] hpricot = Hpricot(response.body) form = hpricot.search('form:first').first || Hpricot::Elem.new('') form.search('input[@type="radio"]').each do |input| directories << self.new(connection, input['value'], false) end self.puts_debug "Directories successfully fetched!" return directories else self.puts_debug "Directories fetch failed!" return false end end |
.list_uri ⇒ Object
19 20 21 |
# File 'lib/image_venue/directory.rb', line 19 def list_uri @list_uri ||= URI.parse(ImageVenue.base_url + '/view_dir.php') end |
.puts_debug(*args) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/image_venue/directory.rb', line 10 def puts_debug(*args) if self.debug? puts(*args) return true else return false end end |
.select_directory_key ⇒ Object
27 28 29 |
# File 'lib/image_venue/directory.rb', line 27 def select_directory_key @select_directory_key ||= 'dir' end |
.select_params(directory_name) ⇒ Object
59 60 61 62 63 |
# File 'lib/image_venue/directory.rb', line 59 def select_params(directory_name) { self.select_directory_key => directory_name } end |
.select_uri ⇒ Object
23 24 25 |
# File 'lib/image_venue/directory.rb', line 23 def select_uri @select_uri ||= URI.parse(ImageVenue.base_url + '/process_change_dir.php') end |
Instance Method Details
#clear_cache ⇒ Object
198 199 200 201 |
# File 'lib/image_venue/directory.rb', line 198 def clear_cache @files = nil self.puts_debug "Directory's cache cleared." end |
#debug? ⇒ Boolean
99 100 101 |
# File 'lib/image_venue/directory.rb', line 99 def debug? (self.class.debug? or self.debug) ? true : false end |
#destroy(force = false, reload = false) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/image_venue/directory.rb', line 140 def destroy(force=false, reload=false) if force or not self.connection.directories(reload).find {|dir| dir.name == self.name }.nil? self.puts_debug "Trying to delete directory: '#{self.name}'" request = Net::HTTP::Post.new(self.class.delete_uri.path) request.form_data = self.class.delete_params(self.name) request.header['cookie'] = [self.connection.] response = Net::HTTP.start(self.class.delete_uri.host, self.class.delete_uri.port) do |http| http.request(request) end if response.is_a?(Net::HTTPSuccess) if self.connection.selected_directory == self.name self.connection.selected_directory = nil end self.puts_debug "Directory successfully deleted!" @is_new = true return true else self.puts_debug "Directory delete failed!" return false end else self.puts_debug "Directory does not exist: '#{self.name}'" return nil end end |
#files(reload = false) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/image_venue/directory.rb', line 189 def files(reload=false) if reload or @files.nil? @files = ImageVenue::File.list(self) else self.puts_debug "Files from cache for directory: '#{self.name}'" end return @files end |
#is_new? ⇒ Boolean
112 113 114 |
# File 'lib/image_venue/directory.rb', line 112 def is_new? @is_new end |
#puts_debug(*args) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/image_venue/directory.rb', line 103 def puts_debug(*args) if self.debug? puts(*args) return true else return false end end |
#save(force = false, reload = false) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/image_venue/directory.rb', line 116 def save(force=false, reload=false) if force or self.connection.directories(reload).find {|dir| dir.name == self.name }.nil? self.puts_debug "Trying to create directory: '#{self.name}'" request = Net::HTTP::Post.new(self.class.create_uri.path) request.form_data = self.class.create_params(self.name) request.header['cookie'] = [self.connection.] response = Net::HTTP.start(self.class.create_uri.host, self.class.create_uri.port) do |http| http.request(request) end if response.is_a?(Net::HTTPSuccess) and not (response.header['Set-Cookie'].nil? or response.header['Set-Cookie'].empty?) self.connection.selected_directory = self.name self.puts_debug "Directory successfully created and selected!" @is_new = false return true else self.puts_debug "Directory create failed!" return false end else self.puts_debug "Directory already exists: '#{self.name}'" return nil end end |
#select(reselect = false) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/image_venue/directory.rb', line 166 def select(reselect=false) if self.connection.selected_directory != self.name or reselect self.puts_debug "Trying to select directory: '#{self.name}'" request = Net::HTTP::Post.new(self.class.select_uri.path) request.form_data = self.class.select_params(self.name) request.header['cookie'] = [self.connection.] response = Net::HTTP.start(self.class.select_uri.host, self.class.select_uri.port) do |http| http.request(request) end if response.is_a?(Net::HTTPFound) and not (response.header['Set-Cookie'].nil? or response.header['Set-Cookie'].empty?) self.connection.selected_directory = self.name self.puts_debug "Directory successfully selected!" return true else self.puts_debug "Directory select failed!" return false end else self.puts_debug "Directory already selected." return nil end end |