Class: ZipDSL
- Inherits:
-
Object
- Object
- ZipDSL
- Defined in:
- lib/zip_dsl/version.rb,
lib/zip_dsl/zip_dsl.rb
Constant Summary collapse
- VERSION =
"1.3.1"
Instance Attribute Summary collapse
-
#from_root ⇒ Object
readonly
Returns the value of attribute from_root.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#to_root ⇒ Object
readonly
Returns the value of attribute to_root.
Instance Method Summary collapse
- #build(name = nil, &execute_block) ⇒ Object
- #entries_size ⇒ Object
- #entry_exist?(entry_name) ⇒ Boolean
-
#initialize(from_root, to_root, name) ⇒ ZipDSL
constructor
A new instance of ZipDSL.
- #list(dir = ".") ⇒ Object
- #update(name = nil, &execute_block) ⇒ Object
Constructor Details
#initialize(from_root, to_root, name) ⇒ ZipDSL
Returns a new instance of ZipDSL.
4 5 6 7 8 9 10 |
# File 'lib/zip_dsl/zip_dsl.rb', line 4 def initialize from_root, to_root, name @from_root = File.(from_root) @to_root = File.(to_root) @name = name FileUtils.mkdir_p(to_root) unless File.exists? to_root end |
Instance Attribute Details
#from_root ⇒ Object (readonly)
Returns the value of attribute from_root.
2 3 4 |
# File 'lib/zip_dsl/zip_dsl.rb', line 2 def from_root @from_root end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/zip_dsl/zip_dsl.rb', line 2 def name @name end |
#to_root ⇒ Object (readonly)
Returns the value of attribute to_root.
2 3 4 |
# File 'lib/zip_dsl/zip_dsl.rb', line 2 def to_root @to_root end |
Instance Method Details
#build(name = nil, &execute_block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/zip_dsl/zip_dsl.rb', line 12 def build(name=nil, &execute_block) name = name.nil? ? @name : name create_block = lambda { ZipWriter.new(from_root, to_root, name) } destroy_block = lambda {|writer| writer.close } evaluate(create_block, destroy_block, execute_block) end |
#entries_size ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/zip_dsl/zip_dsl.rb', line 38 def entries_size create_block = lambda { ZipReader.new(to_root, name) } destroy_block = lambda {|reader| reader.close } execute_block = lambda { |reader| reader.entries_size } evaluate(create_block, destroy_block, execute_block) end |
#entry_exist?(entry_name) ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'lib/zip_dsl/zip_dsl.rb', line 30 def entry_exist? entry_name create_block = lambda { ZipReader.new(to_root, name) } destroy_block = lambda {|reader| reader.close } execute_block = lambda { |reader| reader.entry_exist?(entry_name) } evaluate(create_block, destroy_block, execute_block) end |
#list(dir = ".") ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/zip_dsl/zip_dsl.rb', line 46 def list dir="." create_block = lambda { ZipReader.new(to_root, name) } destroy_block = lambda {|reader| reader.close } execute_block = lambda { |reader| reader.list(dir) } evaluate(create_block, destroy_block, execute_block) end |
#update(name = nil, &execute_block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/zip_dsl/zip_dsl.rb', line 21 def update(name=nil, &execute_block) name = name.nil? ? @name : name create_block = lambda { ZipUpdater.new(from_root, to_root, name) } destroy_block = lambda {|updater| updater.close } evaluate(create_block, destroy_block, execute_block) end |