sinatra-datamapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinatra-datamapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joshua M. Keyes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Sinatra::DataMapper
2
+
3
+ Integrates DataMapper as a Sinatra extension; provides a some
4
+ syntactic sugar around setting up repositories, models, and
5
+ logging for DataMapper.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'sinatra-datamapper'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sinatra-datamapper
20
+
21
+ ## Settings
22
+
23
+ ### Logging
24
+
25
+ + `:datamapper_log_prefix` sets the prefix of any lines logged.
26
+ + `:datamapper_log_level` sets the logging level of DataMapper.
27
+ + `:datamapper_log_path` sets where log lines should be sent to.
28
+
29
+ ### Repositories
30
+
31
+ To configure repositories, set `:datamapper_repositories` to a
32
+ hash of which the key should be the repository name and the value
33
+ can be either a hash of a URI-like string. The extension passes
34
+ these to `DataMapper#setup`. If unset, defaults to an in-memory
35
+ SQLite3 database bound to the `:default` repository context.
36
+
37
+ ### Models
38
+
39
+ By default, the extension will automatically load any Ruby source
40
+ files in the `models` folder of the application root. Set the
41
+ `:datamapper_models` setting to a path containing your models, or
42
+ to `false` to disable automatic loading.
43
+
44
+ ## Example
45
+
46
+ In `models/post.rb`:
47
+
48
+ class Post
49
+ incude DataMapper::Resource
50
+ property :id, Serial
51
+ property :title, String
52
+ property :content, Text
53
+ end
54
+
55
+ In `application.rb`:
56
+
57
+ #!/usr/bin/env ruby
58
+
59
+ require 'sinatra'
60
+ require 'data_mapper'
61
+ require 'sinatra/datamapper'
62
+
63
+ configure do
64
+ set :datamapper_repositories, { default: 'sqlite3://#{Dir.pwd}/database.db' }
65
+ set :datamapper_log_level, :debug
66
+ end
67
+
68
+ get '/' do
69
+ @posts = Post.all
70
+ haml :posts
71
+ end
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,52 @@
1
+ require 'dm-core'
2
+
3
+ module Sinatra
4
+ module DataMapper
5
+ def self.registered(app)
6
+ # Setup the DataMapper logger information. TODO: Integrate with Sinatra/Rack CommonLogger if possible.
7
+ app.set :datamapper_log_prefix, proc { "[DataMapper #{environment}] " }
8
+ app.set :datamapper_log_path, $stderr
9
+ app.set :datamapper_log_level, :info
10
+
11
+ # Create the logger instance itself.
12
+ ::DataMapper::Logger.new(
13
+ settings.datamapper_log_path,
14
+ settings.datamapper_log_level,
15
+ settings.datamapper_log_prefix
16
+ )
17
+
18
+ # Load all configured repositories, defaulting to an in-memory sqlite3 database.
19
+ app.set :datamapper_repositories, { :default => 'sqlite::memory:' }
20
+
21
+ # Setup each repository, applying any specified naming conventions.
22
+ settings.datamapper_repositories.each do |name, uri_or_options|
23
+ if uri_or_options.is_a?(Hash)
24
+ resource_scheme = uri_or_options.delete(:resource_naming_convention)
25
+ field_scheme = uri_or_options.delete(:field_naming_convention)
26
+ end
27
+
28
+ # Register the repository with DataMapper.
29
+ ::DataMapper.setup(name, uri_or_options).tap do |adapter|
30
+ # Apply resource/field naming conventions if they were defined in the options.
31
+ adapter.resource_naming_convention = resource_scheme if resource_scheme
32
+ adapter.field_naming_convention = field_scheme if field_scheme
33
+ end
34
+ end
35
+
36
+ # If available, load all models within the 'models' folder in the application root.
37
+ app.set :datamapper_models, proc { root && ::File.join(root, 'models') }
38
+
39
+ # If we have any models available, load them.
40
+ if settings.datamapper_models
41
+ import = ::Kernel.method(:require)
42
+ pattern = settings.datamapper_models + '/**/*.rb'
43
+ ::Dir[pattern].each(&import)
44
+ end
45
+
46
+ # Call DataMapper#finalize to initialize all DataMapper internals.
47
+ ::DataMapper.finalize
48
+ end
49
+ end
50
+
51
+ register(::Sinatra::DataMapper)
52
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module DataMapper
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/datamapper/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sinatra-datamapper"
8
+ gem.version = Sinatra::DataMapper::VERSION
9
+
10
+ gem.authors = ["Joshua M. Keyes"]
11
+ gem.email = ["joshua.michael.keyes@gmail.com"]
12
+
13
+ gem.homepage = "https://github.com/jmkeyes/sinatra-datamapper"
14
+ gem.description = %q{Easily integrate DataMapper with Sinatra}
15
+ gem.summary = %q{Sinata/DataMapper Extension}
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.add_dependency 'datamapper', '~> 1.2.0'
23
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-datamapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joshua M. Keyes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: datamapper
16
+ requirement: &13724340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13724340
25
+ description: Easily integrate DataMapper with Sinatra
26
+ email:
27
+ - joshua.michael.keyes@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - lib/sinatra/datamapper.rb
38
+ - lib/sinatra/datamapper/version.rb
39
+ - sinatra-datamapper.gemspec
40
+ homepage: https://github.com/jmkeyes/sinatra-datamapper
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.15
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Sinata/DataMapper Extension
64
+ test_files: []
65
+ has_rdoc: