confluencer 0.3.1 → 0.4.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/.document CHANGED
@@ -1,5 +1,3 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
1
+ README
5
2
  LICENSE
3
+ lib/**/*.rb
File without changes
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/rgabo/confluencer"
12
12
  gem.authors = ["Gabor Ratky"]
13
13
  gem.add_development_dependency "rspec", ">= 1.3.0"
14
+ gem.add_runtime_dependency "log4r", ">= 1.1.7"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.1
@@ -2,6 +2,7 @@
2
2
  gemcutter -v0.5.0
3
3
  git -v1.2.5
4
4
  jeweler -v1.4.0
5
- json_pure -v1.4.2
5
+ json_pure -v1.4.3
6
+ log4r -v1.1.7
6
7
  rspec -v1.3.0
7
8
  rubyforge -v2.0.4
@@ -5,23 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{confluencer}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gabor Ratky"]
12
- s.date = %q{2010-05-12}
12
+ s.date = %q{2010-05-13}
13
13
  s.description = %q{ActiveRecord-like classes to access Confluence through XMLRPC.}
14
14
  s.email = %q{rgabo@rgabostyle.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
22
  ".rvmrc",
23
23
  "LICENSE",
24
- "README.rdoc",
24
+ "README",
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "confluencer.gems",
@@ -71,11 +71,14 @@ Gem::Specification.new do |s|
71
71
 
72
72
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
73
  s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
74
+ s.add_runtime_dependency(%q<log4r>, [">= 1.1.7"])
74
75
  else
75
76
  s.add_dependency(%q<rspec>, [">= 1.3.0"])
77
+ s.add_dependency(%q<log4r>, [">= 1.1.7"])
76
78
  end
77
79
  else
78
80
  s.add_dependency(%q<rspec>, [">= 1.3.0"])
81
+ s.add_dependency(%q<log4r>, [">= 1.1.7"])
79
82
  end
80
83
  end
81
84
 
@@ -1,33 +1,32 @@
1
1
  module Confluence
2
2
  class Bookmark < Page
3
- attr_reader :bookmark_url, :description
3
+ attr_accessor :bookmark_url, :description
4
4
 
5
5
  def initialize(hash)
6
- super(hash)
6
+ # set and delete bookmark_url and description
7
+ @bookmark_url = hash.delete :bookmark_url
8
+ @description = hash.delete :description
7
9
 
8
- # if no content, try to use hash to initialize, delete in the process
9
- unless content
10
- self.bookmark_url = attributes.delete :bookmark_url
11
- self.description = attributes.delete :description
12
- else
13
- # parse bookmark_url and description out of content
14
- @bookmark_url = content[/\{bookmark:url=([^\}]+)\}/, 1]
15
- @description = content[/\{bookmark.*\}([^\{]*)\{bookmark\}/, 1]
16
- end
10
+ # initialize page
11
+ super(hash)
17
12
  end
18
13
 
19
- def bookmark_url=(value)
20
- @bookmark_url = value
21
-
22
- # update content with new bookmark_url
23
- update_content
14
+ def [](attr)
15
+ case attr
16
+ when :bookmark_url: @bookmark_url
17
+ when :description: @description
18
+ else
19
+ super(attr)
20
+ end
24
21
  end
25
22
 
26
- def description=(value)
27
- @description = value
28
-
29
- # update content with new description
30
- update_content
23
+ def []=(attr, value)
24
+ case attr
25
+ when :bookmark_url: @bookmark_url = value
26
+ when :description: @description = value
27
+ else
28
+ super(attr, value)
29
+ end
31
30
  end
32
31
 
33
32
  def store
@@ -38,8 +37,24 @@ module Confluence
38
37
  super
39
38
  end
40
39
 
40
+ def to_hash
41
+ page_hash = super
42
+
43
+ if page_hash.key? "content"
44
+ page_hash["content"] << "\n" << bookmark_content
45
+ else
46
+ page_hash["content"] = bookmark_content
47
+ end
48
+
49
+ page_hash
50
+ end
51
+
41
52
  private
42
53
 
54
+ def bookmark_content
55
+ "{bookmark:url=#{@bookmark_url}}#{@description}{bookmark}"
56
+ end
57
+
43
58
  def self.find_criteria(args)
44
59
  result = super(args) || begin
45
60
  if args.key? :space
@@ -50,9 +65,5 @@ module Confluence
50
65
 
51
66
  result
52
67
  end
53
-
54
- def update_content
55
- self.content = "{bookmark:url=#{@bookmark_url}}#{@description}{bookmark}"
56
- end
57
68
  end
58
69
  end
@@ -1,5 +1,25 @@
1
1
  module Confluence
2
2
  class Page < Record
3
+ class Details < Hash
4
+ attr_reader :label
5
+
6
+ def initialize(label)
7
+ @label = label
8
+ end
9
+
10
+ def to_s
11
+ # details macro
12
+ content = "{details:label=#{label}}\n"
13
+
14
+ each_pair do |key, value|
15
+ content << "#{key}=#{value}\n"
16
+ end
17
+
18
+ # end of details macro
19
+ content << "{details}"
20
+ end
21
+ end
22
+
3
23
  extend Findable
4
24
 
5
25
  record_attr_accessor :id => :page_id
@@ -8,7 +28,21 @@ module Confluence
8
28
  record_attr_accessor :title, :creator, :modifier, :content
9
29
  record_attr_accessor :created, :modified, :version
10
30
  record_attr_accessor :url
31
+
32
+ def initialize(hash)
33
+ super(hash)
34
+
35
+ @details = []
36
+ end
37
+
38
+ def details(label)
39
+ unless result = @details.find {|d| d.label == label}
40
+ @details << (result = Details.new(label))
41
+ end
11
42
 
43
+ result
44
+ end
45
+
12
46
  def children(klass = self.class)
13
47
  children = client.getChildren(page_id)
14
48
  children.collect { |child| klass.find(:id => child["id"]) } if children
@@ -31,7 +65,7 @@ module Confluence
31
65
  end
32
66
 
33
67
  # reinitialize page after storing it
34
- initialize(client.storePage(attributes))
68
+ initialize(client.storePage(self.to_hash))
35
69
 
36
70
  # return self
37
71
  self
@@ -41,8 +75,26 @@ module Confluence
41
75
  client.removePage(page_id)
42
76
  end
43
77
 
78
+ def to_hash
79
+ # record hash
80
+ record_hash = super
81
+
82
+ # always include content in hash
83
+ record_hash['content'] ||= ''
84
+
85
+ # prepend details sections before content
86
+ record_hash['content'].insert(0, details_content + "\n") if details_content
87
+
88
+ # result
89
+ record_hash
90
+ end
91
+
44
92
  private
45
93
 
94
+ def details_content
95
+ @details.join("\n") unless @details.empty?
96
+ end
97
+
46
98
  def self.find_all
47
99
  raise ArgumentError, "Cannot find all pages, find by id or title instead."
48
100
  end
@@ -44,12 +44,12 @@ module Confluence
44
44
  end
45
45
  end
46
46
 
47
+ # Returns the the Confluence API client.
48
+ #
47
49
  def client
48
50
  Record.client
49
51
  end
50
52
 
51
- attr_accessor :attributes
52
-
53
53
  # Initializes a new record.
54
54
  #
55
55
  # ==== Parameters
@@ -77,10 +77,14 @@ module Confluence
77
77
  self[:id]
78
78
  end
79
79
 
80
+ # Retrieves the labels of the record.
81
+ #
80
82
  def labels
81
83
  @labels ||= client.getLabelsById(record_id).collect {|label| label["name"]}
82
84
  end
83
85
 
86
+ # Sets the labels of the record.
87
+ #
84
88
  def labels=(value)
85
89
  removed_labels = labels - value
86
90
  added_labels = value - labels
@@ -90,5 +94,11 @@ module Confluence
90
94
 
91
95
  @labels = value
92
96
  end
97
+
98
+ def to_hash
99
+ hash = Hash.new
100
+ @attributes.each { |key, value| hash[key.to_s] = value }
101
+ hash
102
+ end
93
103
  end
94
104
  end
@@ -1,4 +1,35 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
3
  describe Confluence::Bookmark do
4
+ it "should initialize bookmark_url and description from hash" do
5
+ bookmark = Confluence::Bookmark.new :bookmark_url => 'http://github.com/rgabo/confluencer', :description => 'Home sweet home'
6
+
7
+ bookmark.bookmark_url.should == 'http://github.com/rgabo/confluencer'
8
+ bookmark.description.should == 'Home sweet home'
9
+ end
10
+
11
+ it "should get and set bookmark_url and description using #[]" do
12
+ bookmark = Confluence::Bookmark.new :bookmark_url => 'http://github.com/rgabo/confluencer', :description => 'Home sweet home'
13
+
14
+ # bookmark_url and description should not be available as ordinary attributes in the hash
15
+ bookmark[:bookmark_url].should == 'http://github.com/rgabo/confluencer'
16
+ bookmark[:description].should == 'Home sweet home'
17
+
18
+ bookmark[:bookmark_url] = 'http://github.com/rgabo'
19
+ bookmark[:description] = 'rgabo @ Github'
20
+
21
+ bookmark[:bookmark_url].should == 'http://github.com/rgabo'
22
+ bookmark[:description].should == 'rgabo @ Github'
23
+
24
+ bookmark.bookmark_url.should == 'http://github.com/rgabo'
25
+ bookmark.description.should == 'rgabo @ Github'
26
+ end
27
+
28
+ it "should not include bookmark_url and description in to_hash" do
29
+ bookmark = Confluence::Bookmark.new :bookmark_url => 'http://github.com/rgabo/confluencer', :description => 'Home sweet home', :title => "Page title"
30
+
31
+ bookmark.to_hash.key?('bookmark_url').should be_false
32
+ bookmark.to_hash.key?('description').should be_false
33
+ bookmark.to_hash.key?('title').should be_true
34
+ end
4
35
  end
@@ -74,19 +74,37 @@ describe Confluence::Page do
74
74
  page = store_test_page
75
75
 
76
76
  new_session do
77
- # create test page with same title but updated content
78
- updated_page = create_test_page "updated content"
77
+ # create test page with same title but updated content
78
+ updated_page = create_test_page "updated content"
79
+
80
+ updated_page.page_id.should be_nil
81
+ updated_page.title.should == page.title
82
+ updated_page.space.should == page.space
79
83
 
80
- updated_page.page_id.should be_nil
81
- updated_page.title.should == page.title
82
- updated_page.space.should == page.space
84
+ # store page
85
+ updated_page.store
83
86
 
84
- # store page
85
- updated_page.store
87
+ # assert version
88
+ updated_page.version.should > page.version
89
+ updated_page.content.should == "updated content"
90
+ end
91
+ end
92
+
93
+ it "should keep metadata for the page" do
94
+ page = store_test_page
95
+
96
+ # set :creator in {details:label=bender} to 'rgabo'
97
+ page.details(:confluencer)[:creator] = 'rgabo'
98
+
99
+ page.details(:confluencer)[:creator].should == 'rgabo'
100
+ end
101
+
102
+ it "should include metadata in content of the page" do
103
+ page = store_test_page
86
104
 
87
- # assert version
88
- updated_page.version.should > page.version
89
- updated_page.content.should == "updated content"
90
- end
105
+ # set :creator in {details:label=bender} to 'rgabo'
106
+ page.details(:confluencer)[:creator] = 'rgabo'
107
+
108
+ page.to_hash['content'].should include("{details:label=confluencer}\ncreator=rgabo\n{details}")
91
109
  end
92
110
  end
@@ -15,9 +15,29 @@ describe Confluence::Record do
15
15
  record[:string].should == 'works'
16
16
  end
17
17
 
18
+ it "should return attribute values" do
19
+ record = Confluence::Record.new(:key => 'value', 'string_key' => 'string_value')
20
+
21
+ record[:key].should == 'value'
22
+ record[:string_key].should == 'string_value' # attributes with string keys should be accessible with symbols
23
+ end
24
+
25
+ it "should set attribute values" do
26
+ record = Confluence::Record.new
27
+ record[:key] = 'value'
28
+
29
+ record[:key].should == 'value'
30
+ end
31
+
18
32
  it "should return the id of the record" do
19
33
  record = Confluence::Record.new 'id' => '12345'
20
34
 
21
35
  record.record_id.should == '12345'
22
36
  end
37
+
38
+ it "should return a string-keyed hash of its attributes" do
39
+ record = Confluence::Record.new :key => 'value'
40
+
41
+ record.to_hash.should == {'key' => 'value'}
42
+ end
23
43
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 1
9
- version: 0.3.1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gabor Ratky
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-12 00:00:00 +02:00
17
+ date: 2010-05-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -31,6 +31,20 @@ dependencies:
31
31
  version: 1.3.0
32
32
  type: :development
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: log4r
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 1
44
+ - 7
45
+ version: 1.1.7
46
+ type: :runtime
47
+ version_requirements: *id002
34
48
  description: ActiveRecord-like classes to access Confluence through XMLRPC.
35
49
  email: rgabo@rgabostyle.com
36
50
  executables: []
@@ -39,13 +53,13 @@ extensions: []
39
53
 
40
54
  extra_rdoc_files:
41
55
  - LICENSE
42
- - README.rdoc
56
+ - README
43
57
  files:
44
58
  - .document
45
59
  - .gitignore
46
60
  - .rvmrc
47
61
  - LICENSE
48
- - README.rdoc
62
+ - README
49
63
  - Rakefile
50
64
  - VERSION
51
65
  - confluencer.gems