Permalink
Browse files

Draft some specs and code

  • Loading branch information...
0 parents commit 3250b368d1543db61a654ab79aa52a12ca76dfa1 @jhchabran jhchabran committed Jul 19, 2012
Showing with 221 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE
  4. +29 −0 README.md
  5. +6 −0 Rakefile
  6. +7 −0 lib/vintner.rb
  7. +36 −0 lib/vintner/property.rb
  8. +28 −0 lib/vintner/representer.rb
  9. +3 −0 lib/vintner/version.rb
  10. +4 −0 spec/spec_helper.rb
  11. +44 −0 spec/vintner/representer_spec.rb
  12. +21 −0 vintner.gemspec
@@ -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
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in vintner.gemspec
+gemspec
22 LICENSE
@@ -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.
@@ -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
@@ -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
@@ -0,0 +1,7 @@
+require "vintner/version"
+require "vintner/property"
+require "vintner/representer"
+
+module Vintner
+ # Your code goes here...
+end
@@ -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
@@ -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
@@ -0,0 +1,3 @@
+module Vintner
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,4 @@
+require 'vintner'
+
+RSpec.configure do |config|
+end
@@ -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
@@ -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 = ["jh@chabran.fr"]
+ 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.