reply 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem 'rspec'
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 1.8.7"
13
+ gem 'active_attr', '~> 0.8'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ active_attr (0.8.2)
5
+ activemodel (>= 3.0.2, < 4.1)
6
+ activesupport (>= 3.0.2, < 4.1)
7
+ activemodel (4.0.0)
8
+ activesupport (= 4.0.0)
9
+ builder (~> 3.1.0)
10
+ activesupport (4.0.0)
11
+ i18n (~> 0.6, >= 0.6.4)
12
+ minitest (~> 4.2)
13
+ multi_json (~> 1.3)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 0.3.37)
16
+ addressable (2.3.5)
17
+ atomic (1.1.14)
18
+ builder (3.1.4)
19
+ diff-lcs (1.2.4)
20
+ faraday (0.8.8)
21
+ multipart-post (~> 1.2.0)
22
+ git (1.2.6)
23
+ github_api (0.10.1)
24
+ addressable
25
+ faraday (~> 0.8.1)
26
+ hashie (>= 1.2)
27
+ multi_json (~> 1.4)
28
+ nokogiri (~> 1.5.2)
29
+ oauth2
30
+ hashie (2.0.5)
31
+ highline (1.6.19)
32
+ httpauth (0.2.0)
33
+ i18n (0.6.5)
34
+ jeweler (1.8.7)
35
+ builder
36
+ bundler (~> 1.0)
37
+ git (>= 1.2.5)
38
+ github_api (= 0.10.1)
39
+ highline (>= 1.6.15)
40
+ nokogiri (= 1.5.10)
41
+ rake
42
+ rdoc
43
+ json (1.8.0)
44
+ jwt (0.1.8)
45
+ multi_json (>= 1.5)
46
+ minitest (4.7.5)
47
+ multi_json (1.8.0)
48
+ multi_xml (0.5.5)
49
+ multipart-post (1.2.0)
50
+ nokogiri (1.5.10)
51
+ oauth2 (0.9.2)
52
+ faraday (~> 0.8)
53
+ httpauth (~> 0.2)
54
+ jwt (~> 0.1.4)
55
+ multi_json (~> 1.0)
56
+ multi_xml (~> 0.5)
57
+ rack (~> 1.2)
58
+ rack (1.5.2)
59
+ rake (10.1.0)
60
+ rdoc (3.12.2)
61
+ json (~> 1.4)
62
+ rspec (2.14.1)
63
+ rspec-core (~> 2.14.0)
64
+ rspec-expectations (~> 2.14.0)
65
+ rspec-mocks (~> 2.14.0)
66
+ rspec-core (2.14.5)
67
+ rspec-expectations (2.14.3)
68
+ diff-lcs (>= 1.1.3, < 2.0)
69
+ rspec-mocks (2.14.3)
70
+ thread_safe (0.1.3)
71
+ atomic
72
+ tzinfo (0.3.37)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ active_attr (~> 0.8)
79
+ bundler (~> 1.0)
80
+ jeweler (~> 1.8.7)
81
+ rdoc (~> 3.12)
82
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Sebastian
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = reply
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to reply
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Sebastian. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "reply"
18
+ gem.homepage = "http://github.com/sporto/reply"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{An standarized reply object}
21
+ gem.description = %Q{An standarized reply object}
22
+ gem.email = "s@porto5.com"
23
+ gem.authors = ["Sebastian Porto"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ # require 'rcov/rcovtask'
36
+ # Rcov::RcovTask.new do |test|
37
+ # test.libs << 'test'
38
+ # test.pattern = 'test/**/test_*.rb'
39
+ # test.verbose = true
40
+ # test.rcov_opts << '--exclude "gems/*"'
41
+ # end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "reply #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,72 @@
1
+ class Reply
2
+ attr_accessor :status, :messages, :data
3
+
4
+ STATUS_ERROR = 0
5
+ STATUS_SUCCESS = 1
6
+ STATUS_WARNING = 2
7
+
8
+ def initialize(params={})
9
+ @messages = params[:messages] || []
10
+ @status = params[:status] || STATUS_SUCCESS
11
+ @data = params[:data] || {}
12
+ end
13
+
14
+ def clear_messages
15
+ @messages.clear
16
+ end
17
+
18
+ def add_message(message)
19
+ @messages << message
20
+ end
21
+
22
+ def add_messages(array)
23
+ @messages = @messages | array
24
+ end
25
+
26
+ def replace_messages(array)
27
+ @messages = array
28
+ end
29
+
30
+ def replace_messages_with_errors_for(object)
31
+ @messages = object.errors.full_messages
32
+ end
33
+
34
+ def add_error(message)
35
+ add_message(message)
36
+ mark_as_error
37
+ end
38
+
39
+ def add_errors(array)
40
+ add_messages(array)
41
+ mark_as_error
42
+ end
43
+
44
+ def mark_as_error
45
+ @status = STATUS_ERROR
46
+ end
47
+ alias :error! :mark_as_error
48
+
49
+ def mark_as_warning
50
+ @status = STATUS_WARNING
51
+ end
52
+ alias :warning! :mark_as_warning
53
+
54
+ def mark_as_success
55
+ @status = STATUS_SUCCESS
56
+ end
57
+ alias :success! :mark_as_success
58
+
59
+ def success?
60
+ @status == STATUS_SUCCESS
61
+ end
62
+ alias :successful? :success?
63
+
64
+ def error?
65
+ @status == STATUS_ERROR
66
+ end
67
+ alias :failure? :error?
68
+
69
+ def warning?
70
+ @status == STATUS_WARNING
71
+ end
72
+ end
data/lib/reply.rb ADDED
@@ -0,0 +1 @@
1
+ require "reply/reply"
data/reply.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "reply"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sebastian Porto"]
12
+ s.date = "2013-09-25"
13
+ s.description = "An standarized reply object"
14
+ s.email = "s@porto5.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/reply.rb",
29
+ "lib/reply/reply.rb",
30
+ "reply.gemspec",
31
+ "spec/lib/reply/reply_spec.rb",
32
+ "spec/spec_helper.rb",
33
+ "test/helper.rb",
34
+ "test/test_reply.rb"
35
+ ]
36
+ s.homepage = "http://github.com/sporto/reply"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.25"
40
+ s.summary = "An standarized reply object"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
50
+ s.add_development_dependency(%q<active_attr>, ["~> 0.8"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
56
+ s.add_dependency(%q<active_attr>, ["~> 0.8"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
63
+ s.add_dependency(%q<active_attr>, ["~> 0.8"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Reply do
4
+
5
+ class Monkey
6
+ include ActiveAttr::BasicModel
7
+ include ActiveAttr::Attributes
8
+
9
+ attribute :name
10
+
11
+ validates :name, presence: true
12
+ end
13
+
14
+ let(:reply) { Reply.new }
15
+ let(:invalid_object) { Monkey.new }
16
+
17
+ it "is invalid" do
18
+ expect(invalid_object).not_to be_valid
19
+ end
20
+
21
+ it "is successful by default" do
22
+ expect(reply).to be_successful
23
+ end
24
+
25
+ describe ".add_error" do
26
+ before do
27
+ reply.add_error("Error")
28
+ end
29
+
30
+ it "adds the error to the messages" do
31
+ expect(reply.messages.size).to eq(1)
32
+ end
33
+
34
+ it "marks the reply as failure" do
35
+ expect(reply).to be_failure
36
+ end
37
+ end
38
+
39
+ describe ".add_errors" do
40
+ before do
41
+ reply.add_errors(["Error", "Another Error"])
42
+ end
43
+
44
+ it "adds the error to the messages" do
45
+ expect(reply.messages.size).to eq(2)
46
+ end
47
+
48
+ it "marks the reply as failure" do
49
+ expect(reply).to be_failure
50
+ end
51
+ end
52
+
53
+ describe ".replace_messages_with_errors_for" do
54
+ before do
55
+ invalid_object.valid?
56
+ reply.replace_messages_with_errors_for(invalid_object)
57
+ end
58
+
59
+ it "copies the messages" do
60
+ expect(reply.messages.size).to eq(1)
61
+ end
62
+ end
63
+
64
+ describe ".mark_as_error" do
65
+ it "marks the reply as error" do
66
+ reply.mark_as_error
67
+ expect(reply).to be_failure
68
+ end
69
+ end
70
+
71
+ describe ".error!" do
72
+ it "marks the reply as error" do
73
+ reply.error!
74
+ expect(reply).to be_failure
75
+ end
76
+ end
77
+
78
+ describe ".mark_as_success" do
79
+ it "marks the reply as success" do
80
+ reply.mark_as_success
81
+ expect(reply).to be_successful
82
+ end
83
+ end
84
+
85
+ describe ".success!" do
86
+ it "marks the reply as success" do
87
+ reply.success!
88
+ expect(reply).to be_successful
89
+ end
90
+ end
91
+
92
+ describe ".mark_as_warning" do
93
+ it "marks the reply as warning" do
94
+ reply.mark_as_warning
95
+ expect(reply).to be_warning
96
+ end
97
+ end
98
+
99
+ describe ".warning!" do
100
+ it "marks the reply as warning" do
101
+ reply.warning!
102
+ expect(reply).to be_warning
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+
6
+ require 'active_attr'
7
+
8
+ require File.expand_path('../../lib/reply', __FILE__)
9
+ #
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'reply'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestReply < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sebastian Porto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.7
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.7
78
+ - !ruby/object:Gem::Dependency
79
+ name: active_attr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.8'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.8'
94
+ description: An standarized reply object
95
+ email: s@porto5.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.rdoc
101
+ files:
102
+ - .document
103
+ - .rspec
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ - Rakefile
109
+ - VERSION
110
+ - lib/reply.rb
111
+ - lib/reply/reply.rb
112
+ - reply.gemspec
113
+ - spec/lib/reply/reply_spec.rb
114
+ - spec/spec_helper.rb
115
+ - test/helper.rb
116
+ - test/test_reply.rb
117
+ homepage: http://github.com/sporto/reply
118
+ licenses:
119
+ - MIT
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ segments:
131
+ - 0
132
+ hash: 510463183428051726
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.25
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: An standarized reply object
145
+ test_files: []