oym 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: b88b09af92033dd763acc0e69c40a9f3485dedb7
4
- data.tar.gz: 38aef6bc93672b40bc39a53d34ff387698ae4dc7
3
+ metadata.gz: 7d9db808de3b6c09f89a5638a9b045ef625d30a2
4
+ data.tar.gz: c26df54f8708f11833f0839405dce82e29bccaaa
5
5
  SHA512:
6
- metadata.gz: 9d6046f5418644af78e9f22c06f8f143ab447a4fd5241ca4e73a4bedc0a0d0cbff4a3eaf9567dd27254efed97692f15ae125c0884409aee31e6f8e4b24d4b308
7
- data.tar.gz: 258c460f543c9cf693af6b11129fdad461b7166a5d4415b130ac8ba5c62a81fd594a26bdc49d9b03c639d8b02294ceb5146ffa30b6b1a507888dad4b318061af
6
+ metadata.gz: 5c067a0a1be699bdc4ed40124e3c56cde4d29a43761af2502ac05849655a7513e9c064e051c81ba9640be554612fc5d068a3a70017bd3daac59774800b0aff48
7
+ data.tar.gz: 1bf763824da03dd52902e12263e3eb4ecffe62b8c71ece0cd0dc7bb3d7438ae16791ae4aed3876cfb5e27e23088eabb1b1c6a3405c999d2c75a6e0fd3b7ba6c2
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Oym
2
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/oym`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Object yaml mapper.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
7
6
  ## Installation
8
7
 
@@ -32,7 +31,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
31
 
33
32
  ## Contributing
34
33
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/oym. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hkdnet/oym.
36
35
 
37
36
 
38
37
  ## License
data/lib/oym.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "oym/version"
2
-
3
- module Oym
4
- # Your code goes here...
5
- end
1
+ require 'oym/errors'
2
+ require 'oym/resource'
3
+ require 'oym/attribute'
4
+ require 'oym/base'
5
+ require 'oym/version'
@@ -0,0 +1,26 @@
1
+ module Oym
2
+ class Attribute
3
+ attr_accessor :name
4
+ attr_accessor :klass
5
+ attr_accessor :array
6
+
7
+ def initialize(name, klass, array)
8
+ @name = name
9
+ @klass = klass
10
+ @array = array
11
+ end
12
+
13
+ def key
14
+ "#{@name}="
15
+ end
16
+
17
+ def value_from(data)
18
+ raw = data[name.to_s]
19
+ return raw unless klass
20
+ unless klass.respond_to?(:from_data)
21
+ raise "#{klass} is specified as Oym::Attribute's klass, but #{klass} does not respond to from_data"
22
+ end
23
+ array ? raw.map { |e| klass.from_data(e) } : klass.from_data(raw)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Oym
2
+ class Base
3
+ extend Oym::Resource
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module Oym
2
+ module Errors
3
+ class BaseError < StandardError
4
+ end
5
+
6
+ class FileMissingError < BaseError
7
+ def initialize(path)
8
+ @path = path
9
+ end
10
+
11
+ def message
12
+ "No such file: #{@path}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module Oym
2
+ module Resource
3
+ def attribute(name, klass: nil, array: false)
4
+ attr_accessor name
5
+ oym_attributes.push(Oym::Attribute.new(name, klass, array))
6
+ end
7
+
8
+ def oym_attributes
9
+ @oym_attributes ||= []
10
+ end
11
+
12
+ def from_yaml(path)
13
+ raise Oym::Errors::FileMissingError, path unless File.exist?(path)
14
+ require 'yaml'
15
+ from_data(YAML.load_file(path))
16
+ end
17
+
18
+ def from_data(data)
19
+ initial_resource do |e|
20
+ oym_attributes.each do |attr|
21
+ e.send(attr.key, attr.value_from(data))
22
+ end
23
+ end
24
+ end
25
+
26
+ def initial_resource
27
+ ret = new
28
+ yield ret
29
+ ret
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Oym
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1".freeze
3
3
  end
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
+ spec.add_dependency "activesupport", "~> 5.0.0"
28
29
  spec.add_development_dependency "bundler", "~> 1.12"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
30
31
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oym
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
  - hkdnet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-04 00:00:00.000000000 Z
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,7 +76,6 @@ files:
62
76
  - ".gitignore"
63
77
  - ".rspec"
64
78
  - ".travis.yml"
65
- - CODE_OF_CONDUCT.md
66
79
  - Gemfile
67
80
  - LICENSE.txt
68
81
  - README.md
@@ -70,6 +83,10 @@ files:
70
83
  - bin/console
71
84
  - bin/setup
72
85
  - lib/oym.rb
86
+ - lib/oym/attribute.rb
87
+ - lib/oym/base.rb
88
+ - lib/oym/errors.rb
89
+ - lib/oym/resource.rb
73
90
  - lib/oym/version.rb
74
91
  - oym.gemspec
75
92
  homepage: https://github.com/hkdnet/oym
@@ -1,49 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
7
-
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
12
-
13
- Examples of unacceptable behavior by participants include:
14
-
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
18
- * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
22
-
23
- Project maintainers have the right and responsibility to remove, edit, or
24
- reject comments, commits, code, wiki edits, issues, and other contributions
25
- that are not aligned to this Code of Conduct, or to ban temporarily or
26
- permanently any contributor for other behaviors that they deem inappropriate,
27
- threatening, offensive, or harmful.
28
-
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
33
-
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
36
-
37
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at hkdnet@users.noreply.github.com. All
39
- complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
43
-
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
47
-
48
- [homepage]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/