From 3250b368d1543db61a654ab79aa52a12ca76dfa1 Mon Sep 17 00:00:00 2001 From: "JH. Chabran" Date: Thu, 19 Jul 2012 02:01:02 +0200 Subject: [PATCH] Draft some specs and code --- .gitignore | 17 ++++++++++++ Gemfile | 4 +++ LICENSE | 22 ++++++++++++++++ README.md | 29 +++++++++++++++++++++ Rakefile | 6 +++++ lib/vintner.rb | 7 +++++ lib/vintner/property.rb | 36 ++++++++++++++++++++++++++ lib/vintner/representer.rb | 28 ++++++++++++++++++++ lib/vintner/version.rb | 3 +++ spec/spec_helper.rb | 4 +++ spec/vintner/representer_spec.rb | 44 ++++++++++++++++++++++++++++++++ vintner.gemspec | 21 +++++++++++++++ 12 files changed, 221 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100644 lib/vintner.rb create mode 100644 lib/vintner/property.rb create mode 100644 lib/vintner/representer.rb create mode 100644 lib/vintner/version.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/vintner/representer_spec.rb create mode 100644 vintner.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c13ac3e --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in vintner.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6cdf4ec --- /dev/null +++ b/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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6616950 --- /dev/null +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..1941f1d --- /dev/null +++ b/Rakefile @@ -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 diff --git a/lib/vintner.rb b/lib/vintner.rb new file mode 100644 index 0000000..fd13296 --- /dev/null +++ b/lib/vintner.rb @@ -0,0 +1,7 @@ +require "vintner/version" +require "vintner/property" +require "vintner/representer" + +module Vintner + # Your code goes here... +end diff --git a/lib/vintner/property.rb b/lib/vintner/property.rb new file mode 100644 index 0000000..cf71d9f --- /dev/null +++ b/lib/vintner/property.rb @@ -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 diff --git a/lib/vintner/representer.rb b/lib/vintner/representer.rb new file mode 100644 index 0000000..5c0fe81 --- /dev/null +++ b/lib/vintner/representer.rb @@ -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 diff --git a/lib/vintner/version.rb b/lib/vintner/version.rb new file mode 100644 index 0000000..b13f94f --- /dev/null +++ b/lib/vintner/version.rb @@ -0,0 +1,3 @@ +module Vintner + VERSION = "0.0.1" +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..677067c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'vintner' + +RSpec.configure do |config| +end diff --git a/spec/vintner/representer_spec.rb b/spec/vintner/representer_spec.rb new file mode 100644 index 0000000..6bff7d9 --- /dev/null +++ b/spec/vintner/representer_spec.rb @@ -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 diff --git a/vintner.gemspec b/vintner.gemspec new file mode 100644 index 0000000..7d28ad4 --- /dev/null +++ b/vintner.gemspec @@ -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