Class: ZipDSL
- Inherits:
-
Object
- Object
- ZipDSL
- Includes:
- MetaMethods
- Defined in:
- lib/zip_dsl/version.rb,
lib/zip_dsl/zip_dsl.rb
Constant Summary collapse
- VERSION =
"1.3.3"
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.
8 9 10 11 12 13 14 |
# File 'lib/zip_dsl/zip_dsl.rb', line 8 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.
6 7 8 |
# File 'lib/zip_dsl/zip_dsl.rb', line 6 def from_root @from_root end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/zip_dsl/zip_dsl.rb', line 6 def name @name end |
#to_root ⇒ Object (readonly)
Returns the value of attribute to_root.
6 7 8 |
# File 'lib/zip_dsl/zip_dsl.rb', line 6 def to_root @to_root end |
Instance Method Details
#build(name = nil, &execute_block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/zip_dsl/zip_dsl.rb', line 16 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_dsl(create_block, destroy_block, execute_block) end |
#entries_size ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/zip_dsl/zip_dsl.rb', line 42 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_dsl(create_block, destroy_block, execute_block) end |
#entry_exist?(entry_name) ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/zip_dsl/zip_dsl.rb', line 34 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_dsl(create_block, destroy_block, execute_block) end |
#list(dir = ".") ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/zip_dsl/zip_dsl.rb', line 50 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_dsl(create_block, destroy_block, execute_block) end |
#update(name = nil, &execute_block) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/zip_dsl/zip_dsl.rb', line 25 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_dsl(create_block, destroy_block, execute_block) end |