jafry 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ffbe42f6432e9ce9d24ce1692f7e7ce4333aded
4
- data.tar.gz: 7a63cc15a34f237302475ebbbfe6eaec3047d28f
3
+ metadata.gz: a9863ee8e6abf4b6d4f8aba49ea6b41122416f4a
4
+ data.tar.gz: 08a660e1a68d756ab3ee1e9be8490907eab61003
5
5
  SHA512:
6
- metadata.gz: cb3a4ee6b52a3da13111ad045521e980b7756d2f7e9a8a98a1dffaf7144899b6405efeff3d19d7143f10b846c02692279ebb85d6bb387e45d85f9dbc0688e465
7
- data.tar.gz: e2615ae2c8d78dfdf341a98643b9c22cfea51e482243e8795ad5229d13af381caa1a94e2304f7cddebb7231b906b316851cd311d8b1e7b437398991ea585b047
6
+ metadata.gz: 198ae3da6fe4cbd9b397c8fca45012d8ca88aa84ab57f101ea274c703dc35adf93ce57df92a608144a62765c1e672b216f410096666cd55d996eb5ced3ff0b44
7
+ data.tar.gz: 1f508036377378b7d4ef3a8f82e81d0271dfd4ec07e0d3522ecc69aef7827a14487c70066cae020852d2c1e114b559bf1f8babc32447e455f5edefcccf68bfa6
@@ -2,7 +2,6 @@ language: ruby
2
2
  cache: bundler
3
3
 
4
4
  rvm:
5
- - ruby
6
5
  - 2.1.1
7
6
 
8
7
  script: 'bundle exec rake'
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Jafry
2
+ [![Build Status](https://travis-ci.org/igorrKurr/jafry.svg?branch=master)](https://travis-ci.org/igorrKurr/jafry)
3
+ [![Gem Version](https://badge.fury.io/rb/jafry.svg)](http://badge.fury.io/rb/jafry)
4
+ [![Coverage Status](https://img.shields.io/coveralls/igorrKurr/jafry.svg)](https://coveralls.io/r/igorrKurr/jafry?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/igorrKurr/jafry/badges/gpa.svg)](https://codeclimate.com/github/igorrKurr/jafry)
2
6
 
3
- TODO: Write a gem description
7
+ This gem allows you to easily create JSON data fixtures from data schemes you can specify by yourself.
8
+ The main purpose is to stub JSON received form wide range of JSON API's for testing.
9
+ And if you use many API's or kind of difficult one you may want to have a tool for easy creation of tons of JSON data you have.
10
+ And Jafry can help you here.
11
+ Just specify data scheme in json file and then you can change your data easly, wrap it namespaces, build lists, etc.
4
12
 
5
13
  ## Installation
6
14
 
@@ -18,7 +26,10 @@ Or install it yourself as:
18
26
 
19
27
  ## Usage
20
28
 
21
- TODO: Write usage instructions here
29
+ 1. Create file `data_scheme_name.json`.
30
+ 2. Put json data in it.
31
+ 3. In your `spec_helper.rb` require `jafry`: `require "jafry"`.
32
+ 4. Call `Jafry.build('data_scheme_name')` to get object or `Jafry.create('data_scheme_name')` in your spec.
22
33
 
23
34
  ## Contributing
24
35
 
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Jafry::VERSION
9
9
  spec.authors = ["Igor Kur"]
10
10
  spec.email = ["kur91@mail.ru"]
11
- spec.summary = %q{Gem for stub json data}
12
- spec.description = %q{}
11
+ spec.summary = %q{Gem for creating JSON data stubs}
12
+ spec.description = %q{This gem allows you to easily create JSON data fixtures
13
+ from data schemes you can specify by yourself.
14
+ The main purpose is to stub JSON received form wide range of JSON API's.}
13
15
  spec.homepage = ""
14
16
  spec.license = "MIT"
15
17
 
@@ -24,4 +26,5 @@ Gem::Specification.new do |spec|
24
26
  spec.add_development_dependency "coveralls"
25
27
  spec.add_development_dependency "yajl-ruby"
26
28
  spec.add_development_dependency "hashie"
29
+ spec.add_development_dependency "yard"
27
30
  end
@@ -1,13 +1,21 @@
1
1
  require 'jafry/version'
2
2
  require 'jafry/actions'
3
3
 
4
+ # Main Jafry module
5
+ #
6
+ # @attr [String] schemes_path Path to Jafry schemes
7
+
4
8
  module Jafry
5
9
  extend Actions
6
10
 
11
+ # Schemes path attr getter
12
+
7
13
  def self.schemes_path
8
14
  @@schemes_path
9
15
  end
10
16
 
17
+ # Schemes path attr setter
18
+
11
19
  def self.schemes_path=(schemes_path)
12
20
  @@schemes_path = schemes_path
13
21
  end
@@ -1,7 +1,17 @@
1
1
  require 'yajl'
2
2
  require 'jafry/scheme'
3
3
 
4
+ # This module contains main functionality for Jafry
5
+
4
6
  module Actions
7
+ # Return object builded from scheme
8
+
9
+ # @param scheme_name [String] Scheme name
10
+ # @param [Hash] options Options
11
+ # @option options [String] :wrap Namespace to wrap scheme in
12
+ # @return [Scheme] New Scheme object build with pointed options
13
+ # @see Scheme
14
+
5
15
  def build(scheme_name, options={})
6
16
  scheme = Scheme.new(scheme_name)
7
17
  options.each do |attr, value|
@@ -11,16 +21,42 @@ module Actions
11
21
  scheme
12
22
  end
13
23
 
24
+ # Return json from scheme
25
+
26
+ # @param scheme_name [String] Scheme name
27
+ # @param options [Hash] Options
28
+ # @option options [String] :wrap Namespace to wrap json in
29
+ # @return [Scheme] New Scheme object encoded to json
30
+ # @see Scheme
31
+
14
32
  def create(scheme_name, options={})
15
33
  Yajl::Encoder.encode(build(scheme_name, options))
16
34
  end
17
35
 
36
+ # Retun array of Scheme objects
37
+
38
+ # @param scheme_name [String] Scheme name
39
+ # @param count [Integer] Number of objects in array
40
+ # @param options [Hash] Options
41
+ # @option options [String] :wrap Namespace to wrap list in
42
+ # @return [Array] Array of Schemes
43
+ # @see Scheme
44
+
18
45
  def build_list(scheme_name, count, options={})
19
46
  list = []
20
47
  count.times {list << build(scheme_name, options)}
21
48
  list
22
49
  end
23
50
 
51
+ # Retun array of Scheme objects encoded to json
52
+
53
+ # @param scheme_name [String] Scheme name
54
+ # @param count [Integer] Number of objects in array
55
+ # @param options [Hash] Options
56
+ # @option options [String] :wrap Namespace to wrap json list in
57
+ # @return [Array] Json array of schemes
58
+ # @see Scheme
59
+
24
60
  def create_list(scheme_name, count, options={})
25
61
  Yajl::Encoder.encode(build_list(scheme_name, count, options))
26
62
  end
@@ -1,16 +1,48 @@
1
1
  require 'yajl'
2
2
  require 'hashie'
3
3
 
4
+ # Class for parsing json scheme
5
+
4
6
  class Scheme < Hashie::Mash
7
+ #Initialize Scheme
8
+ #
9
+ # @raise [Exception] Raises when json scheme file not found
10
+
5
11
  def initialize(path)
6
- super(Yajl::Parser.new.parse(File.read("#{Jafry.schemes_path}/#{path}.json")))
12
+ begin
13
+ raise "Please, create correct scheme file first" unless File.exists?(build_schemes_path(path))
14
+ super(Yajl::Parser.new.parse(File.read(build_schemes_path(path))))
15
+ rescue Exception => e
16
+ puts e.message
17
+ puts e.backtrace
18
+ end
7
19
  end
8
20
 
21
+ # Return json from scheme
22
+ #
23
+ # @return [String] JSON from scheme
24
+
9
25
  def build
10
26
  Yajl::Encoder.encode self
11
27
  end
12
28
 
13
- def wrap(name)
14
- {"#{name}" => self}
29
+ # Wraps current scheme in specified namespace
30
+ #
31
+ # @return [Hash] Wrapped hash
32
+
33
+ def wrap(namespace)
34
+ {"#{namespace}" => self}
35
+ end
36
+
37
+ private
38
+
39
+ # Method for creating full path to scheme file
40
+ #
41
+ # @private
42
+ # @param scheme [String] Scheme name
43
+ # @return [String] Full path to file
44
+
45
+ def build_schemes_path(scheme)
46
+ "#{Jafry.schemes_path}/#{scheme}.json"
15
47
  end
16
48
  end
@@ -1,3 +1,3 @@
1
1
  module Jafry
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,21 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Scheme do
4
- before(:each) do
4
+ before(:all) {Jafry.schemes_path = '.'}
5
+ context "from existing file" do
6
+ before(:each) do
5
7
  File.open("test.json", 'w+') {|f| f.write(%Q({"name":"test"})) }
6
- Jafry.schemes_path = './'
7
8
  @scheme = Scheme.new('test')
9
+ end
10
+ after(:each) do
11
+ File.delete("test.json")
12
+ end
13
+ it 'initializes from file' do
14
+ expect(@scheme.name).to eq('test')
15
+ end
16
+ it 'builds json' do
17
+ expect(@scheme.build).to eq(%Q({"name":"test"}))
18
+ end
19
+ it 'wraps json' do
20
+ expect(@scheme.wrap("user")).to eq({"user" => {"name" => "test"}})
21
+ end
22
+ it 'builds schemes path' do
23
+ expect(@scheme.send(:build_schemes_path, 'foo')).to eq("./foo.json")
24
+ end
8
25
  end
9
- after(:each) do
10
- File.delete("test.json")
11
- end
12
- it 'initializes from file' do
13
- expect(@scheme.name).to eq('test')
14
- end
15
- it 'builds json' do
16
- expect(@scheme.build).to eq(%Q({"name":"test"}))
17
- end
18
- it 'wraps json' do
19
- expect(@scheme.wrap("user")).to eq({"user" => {"name" => "test"}})
26
+ context "from unexisting file" do
27
+ it "returns `create file` caution" do
28
+ expect { Scheme.new('foo') }.to output(/Please, create correct scheme file first/).to_stdout
29
+ end
20
30
  end
21
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jafry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-10 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,7 +94,24 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: ''
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |-
112
+ This gem allows you to easily create JSON data fixtures
113
+ from data schemes you can specify by yourself.
114
+ The main purpose is to stub JSON received form wide range of JSON API's.
98
115
  email:
99
116
  - kur91@mail.ru
100
117
  executables: []
@@ -139,8 +156,9 @@ rubyforge_project:
139
156
  rubygems_version: 2.2.2
140
157
  signing_key:
141
158
  specification_version: 4
142
- summary: Gem for stub json data
159
+ summary: Gem for creating JSON data stubs
143
160
  test_files:
144
161
  - spec/jafry_spec.rb
145
162
  - spec/scheme_spec.rb
146
163
  - spec/spec_helper.rb
164
+ has_rdoc: