jattrs 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8d0dc26d5cd5ccaedfd6888ba41bb4785398509
4
+ data.tar.gz: 14389682476779270160f73a19a1cb70aece74f0
5
+ SHA512:
6
+ metadata.gz: 49e65f4d27b150ca615512728be6cac21e22d37330779425256d00bb1b41dd9ee1af6bee2e03dd1130639927a36634e9fc006cf4bd679bd55032a3e39cb660c6
7
+ data.tar.gz: b67d54c1dfbc51773d64a37c178cf226ae7774ce283158d587dbc67370576aea64ffd5ce31447eb925d08106484ea277ddf9749de3e6ee8bada3ad1feb7fcaaa
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jattrs.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Jattrs
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jattrs`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jattrs'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jattrs
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/jattrs/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jattrs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/jattrs.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jattrs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jattrs"
8
+ spec.version = Jattrs::VERSION
9
+ spec.authors = ["Mitch Monsen", "Benjamin Kimball", "Michael Archibald", "Nathan Davis", "Jeffrey Thorup"]
10
+ spec.email = ["mmonsen7@gmail.com", "ben@creditera.com", "micharch54@gmail.com", "nbriardavis@gmail.com", "jthorup84@gmail.com"]
11
+ spec.summary = "Convert your json or hash fields into simple Ruby object attributes."
12
+ spec.description = "Simple module to enable JSON or Hash fields to behave like regular Ruby attributes."
13
+ spec.homepage = "https://github.com/blarshk/jattrs"
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.require_paths = ["lib"]
16
+ spec.license = 'MIT'
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.9"
19
+ spec.add_development_dependency "minitest", "~> 5.1"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
@@ -0,0 +1,3 @@
1
+ module Jattrs
2
+ VERSION = "0.1.0"
3
+ end
data/lib/jattrs.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "jattrs/version"
2
+
3
+ module Jattrs
4
+ def self.included(base)
5
+ base.extend(JsonAttributesClassMethods)
6
+ end
7
+
8
+ private
9
+
10
+ module JsonAttributesClassMethods
11
+ def jattr_accessor(field_name, *methods)
12
+ jattr_reader(field_name, methods)
13
+ jattr_writer(field_name, methods)
14
+ end
15
+
16
+ def jattr_reader(field_name, methods)
17
+ methods.each do |method|
18
+ next if respond_to?(method)
19
+
20
+ define_method("#{method}") do
21
+ send(field_name)[method.to_s]
22
+ end
23
+ end
24
+ end
25
+
26
+ def jattr_writer(field_name, methods)
27
+ methods.each do |method|
28
+ next if respond_to?(method)
29
+
30
+ define_method("#{method}=") do |object_value|
31
+ if send(field_name).nil?
32
+ self.send("#{field_name}=", { method.to_s => object_value })
33
+ else
34
+ send(field_name)[method.to_s] = object_value
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jattrs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mitch Monsen
8
+ - Benjamin Kimball
9
+ - Michael Archibald
10
+ - Nathan Davis
11
+ - Jeffrey Thorup
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2015-05-06 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: bundler
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: '1.9'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.9'
31
+ - !ruby/object:Gem::Dependency
32
+ name: minitest
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - "~>"
36
+ - !ruby/object:Gem::Version
37
+ version: '5.1'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '5.1'
45
+ - !ruby/object:Gem::Dependency
46
+ name: rake
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '10.0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '10.0'
59
+ description: Simple module to enable JSON or Hash fields to behave like regular Ruby
60
+ attributes.
61
+ email:
62
+ - mmonsen7@gmail.com
63
+ - ben@creditera.com
64
+ - micharch54@gmail.com
65
+ - nbriardavis@gmail.com
66
+ - jthorup84@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - ".gitignore"
72
+ - ".travis.yml"
73
+ - Gemfile
74
+ - README.md
75
+ - Rakefile
76
+ - bin/console
77
+ - bin/setup
78
+ - jattrs.gemspec
79
+ - lib/jattrs.rb
80
+ - lib/jattrs/version.rb
81
+ homepage: https://github.com/blarshk/jattrs
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Convert your json or hash fields into simple Ruby object attributes.
105
+ test_files: []