gom-core 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 dirk luesebrink
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.
@@ -0,0 +1,18 @@
1
+ = gom-core
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 dirk luesebrink. See LICENSE for details.
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gom-core"
8
+ gem.summary = %Q{basic GOM functionallity}
9
+ gem.description = %Q{this gem includes stuff which is of use for the server as well as for gom scripting clients}
10
+ gem.email = "dirk.luesebrink@gmail.com"
11
+ gem.homepage = "http://github.com/crux/gom-core"
12
+ gem.authors = ["art+com/dirk luesebrink"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION')
40
+ version = File.read('VERSION')
41
+ else
42
+ version = ""
43
+ end
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "gom-core #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1 @@
1
+ require 'gom/core'
@@ -0,0 +1 @@
1
+ require 'gom/core/primitive'
@@ -0,0 +1,55 @@
1
+ module Gom
2
+ module Core
3
+ end
4
+ end
5
+
6
+ class Gom::Core::Primitive
7
+
8
+ Types = {
9
+ "Symbol" => :symbol,
10
+ "Fixnum" => :integer,
11
+ "Bignum" => :integer,
12
+ "BigDecimal" => :decimal,
13
+ "Float" => :float,
14
+ "Date" => :date,
15
+ "DateTime" => :datetime,
16
+ "Time" => :datetime,
17
+ "TrueClass" => :boolean,
18
+ "FalseClass" => :boolean,
19
+ "URI::HTTP" => :uri,
20
+ "URI::HTTPS" => :uri,
21
+ "URI::Generic" => :uri,
22
+ }
23
+
24
+ Parsers = {
25
+ :date => Proc.new { |date| ::Date.parse(date) },
26
+ :datetime => Proc.new { |time| ::DateTime.parse(time) },
27
+ :float => Proc.new { |txt| txt.to_f },
28
+ :integer => Proc.new { |txt| txt.to_i },
29
+ :uri => Proc.new { |s| URI.parse(s) },
30
+ }
31
+
32
+ Formatters = Hash.new(Proc.new{|o|o.to_s}).update(
33
+ :string => Proc.new { |s| s.to_s },
34
+ :date => Proc.new { |date| date.strftime('%Y-%m-%d') }, #.to_s(:db) },
35
+ :datetime => Proc.new { |time|
36
+ # back and forth, trying to 'normalize' the myriad of time formats
37
+ DateTime.parse(time.to_s).strftime
38
+ #DateTime.parse(time.to_s).xmlschema
39
+ #time.xmlschema
40
+ }
41
+ )
42
+
43
+ # text, type -> value
44
+ def self.decode txt, type = :string
45
+ parser = type && Parsers[type.to_sym]
46
+ parser && parser.call(txt) || txt
47
+ end
48
+
49
+ # value -> text, type
50
+ def self.encode value
51
+ type = Types[value.class.name] || :string
52
+ formatter = Formatters[type]
53
+ [ formatter.call(value), type]
54
+ end
55
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__)+'/../../spec_helper'
2
+
3
+ include Gom::Core
4
+
5
+ describe Gom::Core::Primitive do
6
+ it "encode/decode should fail on non supported types" do
7
+ # TODO: test & implementation
8
+ end
9
+
10
+ it "should encode URIs" do
11
+ uri = URI.parse "http://www.artcom.de/"
12
+ Primitive.encode(uri).should == [uri.to_s, :uri]
13
+ uri.should == Primitive.decode(*Primitive.encode(uri))
14
+ end
15
+
16
+ it "should encode intergers" do
17
+ val = rand 1000
18
+ val.should == Primitive.decode(*Primitive.encode(val))
19
+ end
20
+
21
+ it "should encode floats" do
22
+ v_in = rand
23
+ v_out, t = Primitive.encode(v_in)
24
+ v_in.to_s.should == v_out.to_s
25
+ :float.should == t
26
+ end
27
+
28
+ it "should encode datetime" do
29
+ t1 = DateTime.now
30
+ t2 = Primitive.decode(*Primitive.encode(t1))
31
+ t2.should_not == nil
32
+ # compare times as formatted strings cause otherwise lots of weired
33
+ # timezone & time stuff hits us with equal values beeing not considered
34
+ # equal...
35
+ t1.strftime.should == t2.strftime
36
+
37
+ # TODO: to_s with :db seems to be an rails extension...
38
+ #t1.to_s(:db).should == t2.to_s(:db)
39
+ end
40
+
41
+ it "should encode dates" do
42
+ val = Date.today
43
+ val.should == Primitive.decode(*Primitive.encode(val))
44
+ end
45
+
46
+ it "should encode strings" do
47
+ s = "random text string: #{rand}."
48
+ s.should == Primitive.decode(*Primitive.encode(s))
49
+ [s, :string].should == Primitive.encode(s)
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ --backtrace --debugger
@@ -0,0 +1,37 @@
1
+ # figure out where we are being loaded from
2
+ if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
3
+ begin
4
+ raise "foo"
5
+ rescue => e
6
+ puts <<-MSG
7
+ ===================================================
8
+ It looks like spec_helper.rb has been loaded
9
+ multiple times. Normalize the require to:
10
+
11
+ require "spec/spec_helper"
12
+
13
+ Things like File.join and File.expand_path will
14
+ cause it to be loaded multiple times.
15
+
16
+ Loaded this time from:
17
+
18
+ #{e.backtrace.join("\n ")}
19
+ ===================================================
20
+ MSG
21
+ end
22
+ end
23
+
24
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
25
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
26
+ require 'spec'
27
+ require 'spec/autorun'
28
+
29
+ require 'gom/core'
30
+
31
+ Spec::Runner.configure do |config|
32
+ config.before :each do
33
+ end
34
+
35
+ config.after :each do
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gom-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - art+com/dirk luesebrink
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-30 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: this gem includes stuff which is of use for the server as well as for gom scripting clients
26
+ email: dirk.luesebrink@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/gom-core.rb
42
+ - lib/gom/core.rb
43
+ - lib/gom/core/primitive.rb
44
+ - spec/gom/core/primitive_spec.rb
45
+ - spec/spec.opts
46
+ - spec/spec_helper.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/crux/gom-core
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: basic GOM functionallity
75
+ test_files:
76
+ - spec/gom/core/primitive_spec.rb
77
+ - spec/spec_helper.rb