YAMLiner 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,7 +1,8 @@
1
1
  = What is this?
2
2
 
3
- With this library you gives a Hash or an Array instance and it extends this with it's own methods
4
- then you can CRUD on this instance <b>inline YAML</b> line with your specified options.
3
+ This library extends given object instance with it's own methods and then you
4
+ can use this instance to CRUD over files as comment lines in format of <b>inline YAML</b>
5
+ line with your specified options.
5
6
 
6
7
  == Installation
7
8
 
@@ -24,7 +25,7 @@ operation functions #read, #delete!, #write! (creates and updates)
24
25
  you can change :name, :prefix, :postfix for every type of text file
25
26
  comment styles like this:
26
27
 
27
- >> my_hash.yamline_settings(:prefix => '/*', :postfix => '*/', :name => 'my_c_comment')
28
+ >> my_hash.yamline_set(:prefix => '/*', :postfix => '*/', :name => 'my_c_comment')
28
29
  => {:name=>"my_c_comment", :file=>"", :line=>0, :prefix=>"/*", :postfix=>"*/", :writeto=>""}
29
30
  >> my_hash.yamline
30
31
  => "/*my_c_comment--- {:name: selman, :surname: ulug}*/\n"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/YAMLiner.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{YAMLiner}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Selman ULUG"]
12
- s.date = %q{2010-07-17}
12
+ s.date = %q{2010-08-01}
13
13
  s.description = %q{Simple gem that supplies inline YAML CRUD operations that usable by all kind of text files.}
14
14
  s.email = %q{selman.ulug@gmail.com}
15
15
  s.extra_rdoc_files = [
data/lib/yamliner.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #<b>inline YAML</b>.
4
4
  # a = {:name => 'selman', :surname => 'ulug'}
5
5
  # YAMLiner::line a
6
- # a.yamline_settings(:name => 'MyLine')
6
+ # a.yamline_set(:name => 'MyLine')
7
7
  require 'yaml'
8
8
  require 'fileutils'
9
9
 
@@ -24,29 +24,37 @@ module YAMLiner
24
24
  :writeto => '' }
25
25
 
26
26
  objects.each do |object|
27
- if object.kind_of?(Array) or object.kind_of?(Hash)
27
+ if object.respond_to?(:to_yaml)
28
28
  object.extend(YAMLinerActions)
29
- object.instance_variable_set(:@settings, settings)
29
+ object.instance_variable_set(:@yamline_settings, settings)
30
30
  else
31
- raise "only Hash or Array classes supported: #{object.class} not supported"
31
+ raise "#{object.class} do not responding to to_yaml method"
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
36
  #CRUD operation functions and some tools
37
37
  module YAMLinerActions
38
- attr_reader :settings
38
+ attr_reader :yamline_settings
39
39
 
40
40
  #You can get inline YAML only redefining this method
41
41
  def to_yaml_style
42
42
  :inline
43
43
  end
44
44
 
45
+ #aliasing to_yaml_properties to remove our instance variable
46
+ alias to_yaml_properties_orginal to_yaml_properties
47
+
48
+ #removing our yamline_settings instance variable
49
+ def to_yaml_properties
50
+ to_yaml_properties_orginal - [:@yamline_settings]
51
+ end
52
+
45
53
  #Returns generated YAMLiner line
46
54
  # >> a.yamline
47
55
  # => "#YAMLiner--- {:name: selman, :surname: ulug}\n"
48
56
  def yamline
49
- @settings[:prefix] + @settings[:name] + self.to_yaml.chop + @settings[:postfix] + "\n"
57
+ @yamline_settings[:prefix] + @yamline_settings[:name] + to_yaml.chop + @yamline_settings[:postfix] + "\n"
50
58
  end
51
59
 
52
60
  #YAMLiner settings default values
@@ -56,16 +64,16 @@ module YAMLiner
56
64
  # :prefix => '#'
57
65
  # :postfix => ''
58
66
  # :writeto => ''
59
- def yamline_settings(sets = {})
60
- @settings.merge!(sets) unless sets.empty?
67
+ def yamline_set(settings = {})
68
+ @yamline_settings.merge!(settings) unless settings.empty?
61
69
  end
62
70
 
63
71
  #Reads your supplied file/files if successfull returns readed object
64
- # Dir['**/*.txt'].each {|f| a.yamline_settins(:file => f); a.yamline_read }
72
+ # Dir['**/*.txt'].each {|f| a.yamline_set(:file => f); a.yamline_read }
65
73
  def yamline_read(lines = nil, loaded = true)
66
74
  lines = file_lines unless lines
67
75
  return unless lines
68
- matcher = %r{(^#{Regexp.escape(@settings[:prefix] + @settings[:name])})(.*?)(#{Regexp.escape(@settings[:postfix])}$)}
76
+ matcher = %r{(^#{Regexp.escape(@yamline_settings[:prefix] + @yamline_settings[:name])})(.*?)(#{Regexp.escape(@yamline_settings[:postfix])}$)}
69
77
  line_l = []
70
78
  line_s = lines.select {|line| line =~ matcher; line_l << YAML::load($2) if $2 }
71
79
  return if line_s.empty?
@@ -74,18 +82,18 @@ module YAMLiner
74
82
 
75
83
  #Writes the generated YAMLiner line to supplied file/files if there
76
84
  #is a same formated line it deletes and write again.
77
- # a.yamline_settings(:file => 'test.txt')
85
+ # a.yamline_set(:file => 'test.txt')
78
86
  # a.yamline_write!
79
87
  def yamline_write!
80
88
  lines = file_lines || []
81
89
  yamline_delete!(lines) unless lines.empty?
82
- lines.insert(settings[:line], yamline)
90
+ lines.insert(@yamline_settings[:line], yamline)
83
91
  save_file(lines)
84
92
  end
85
93
 
86
94
  #Finds and deletes formatted line/lines from supplied
87
95
  #file/files. if formetted line is not uniq it deletes all of them.
88
- # a.yamline_settings(:file => 'test.txt')
96
+ # a.yamline_set(:file => 'test.txt')
89
97
  # a.yamline_delete!
90
98
  def yamline_delete!(lines = nil)
91
99
  lines = file_lines unless lines
@@ -98,15 +106,15 @@ module YAMLiner
98
106
  private
99
107
 
100
108
  def file_lines
101
- file = @settings[:file]
109
+ file = @yamline_settings[:file]
102
110
  return if file.empty?
103
111
  return unless File.exists?(file)
104
112
  File.readlines(file)
105
113
  end
106
114
 
107
115
  def save_file(temp)
108
- writeto = @settings[:writeto]
109
- writeto = @settings[:file] if writeto.empty?
116
+ writeto = @yamline_settings[:writeto]
117
+ writeto = @yamline_settings[:file] if writeto.empty?
110
118
  File.open(writeto, 'w+') { |file| file.puts temp }
111
119
  true
112
120
  end
@@ -11,21 +11,21 @@ describe "Yamliner" do
11
11
  YAMLiner::line @input
12
12
  end
13
13
 
14
- it "should raise exception other than Array or Hash" do
15
- lambda { s=''; YAMLiner::line s}.should raise_exception
16
- end
14
+ # it "should raise exception other than Array or Hash" do
15
+ # lambda { s=''; YAMLiner::line s}.should raise_exception
16
+ # end
17
17
 
18
18
  it "should return nil when no file specified to read" do
19
19
  @input.yamline_read.should be_nil
20
20
  end
21
21
 
22
22
  it "should return nil when specified file is not available to read" do
23
- @input.yamline_settings(:file => 'not_available.txt')
23
+ @input.yamline_set(:file => 'not_available.txt')
24
24
  @input.yamline_read.should be_nil
25
25
  end
26
26
 
27
27
  it "should read specified file and return nil when no YAMLiner" do
28
- @input.yamline_settings(:file => @test_file)
28
+ @input.yamline_set(:file => @test_file)
29
29
  @input.yamline_read.should be_nil
30
30
  end
31
31
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: YAMLiner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Selman ULUG
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-17 00:00:00 +03:00
18
+ date: 2010-08-01 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency