Skip to content

Commit

Permalink
Draft some specs and code
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchabran committed Jul 19, 2012
0 parents commit 3250b36
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in vintner.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012 JH. Chabran

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Vintner

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'vintner'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vintner

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
task :default => :spec
7 changes: 7 additions & 0 deletions lib/vintner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "vintner/version"
require "vintner/property"
require "vintner/representer"

module Vintner
# Your code goes here...
end
36 changes: 36 additions & 0 deletions lib/vintner/property.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Vintner
class Property
attr_reader :name

def initialize name, &block
@name = name

instance_eval &block if block_given?
end

def import model, value
yield mode, value
end

def export model
yield model
end

def getter_defined?
!!@getter
end

def setter_defined?
!!@setter
end

private
def get &block
@getter = block
end

def set &block
@setter = block
end
end
end
28 changes: 28 additions & 0 deletions lib/vintner/representer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'active_support/concern'
require 'active_support/core_ext'

module Vintner
module Representer
extend ::ActiveSupport::Concern

module ClassMethods
mattr_reader :properties, :collections

def property name, &block
@@properties ||= {}

@@properties[name] = Property.new(name, &block)
end

def collection name, representer
@@collections ||= {}

raise "TODO"
end

def representation &block

end
end
end
end
3 changes: 3 additions & 0 deletions lib/vintner/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Vintner
VERSION = "0.0.1"
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'vintner'

RSpec.configure do |config|
end
44 changes: 44 additions & 0 deletions spec/vintner/representer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

module Vintner
describe Representer do
it "should allow to declare a simple property" do
class Dummy
include Vintner::Representer

property :title
end

Dummy.properties.should include(:title)
end

it "should allow to declare a property with a getter" do
class Dummy
include Vintner::Representer

property :title do
get do |model|
model.formatted_title
end
end
end


Dummy.properties[:title].getter_defined?.should be(true)
end

it "should allow to declare a property with a getter" do
class Dummy
include Vintner::Representer

property :title do
set do |model, value|
model.formatted_title = value
end
end
end

Dummy.properties[:title].setter_defined?.should be(true)
end
end
end
21 changes: 21 additions & 0 deletions vintner.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/vintner/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["JH. Chabran"]
gem.email = ["[email protected]"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.homepage = ""

gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "vintner"
gem.require_paths = ["lib"]
gem.version = Vintner::VERSION

gem.add_dependency 'active_support'
gem.add_dependency 'i18n'
gem.add_development_dependency 'rspec', '~> 2.6'
end

0 comments on commit 3250b36

Please sign in to comment.