vinber 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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +68 -19
  3. data/lib/vinber/version.rb +1 -1
  4. data/lib/vinber.rb +49 -2
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8eebdd44046cbb5ab80ed6b0930c003986533a56
4
- data.tar.gz: 06c0fa039ec44265383ed0da415e697c3024d232
3
+ metadata.gz: 5846099a1282c804d8caee37689c761e2c46e8f4
4
+ data.tar.gz: b06ec6b47bb81c6e8349064513aae54b9e8ef2aa
5
5
  SHA512:
6
- metadata.gz: 95f15907b69f1fabbfcf029c66df1149019d93549da85e89ad80db0bad300a9ba7e316075c2fb496c5f6fd77fa5a3c91537f40888fe934e5ed78c56f75d8b40d
7
- data.tar.gz: 333d2e7d58d84bab06ed9db62b1eb1c597442baea9968b0dcd7b0b52342fb1102996e59c9eac88002b02d59741e378000aa2df8cb1268a3c8789d6292feb3ae7
6
+ metadata.gz: 40dca19b242327e0c29915d62a528a1983f5b632d7ae6667d359809045402eb30f80351ac2549608fd6d8b69bbe7eb0e36c1a0a72abeb1c4ef7d81a05d6ab0de
7
+ data.tar.gz: 4a73b9e8f2b025307a0a351817a6c9206b0757eb1872218270e618b71b0d21cee1af459f00f59767795e4270c0a50c7f499fe1d5f534b88b3497484529a19ac8
data/README.md CHANGED
@@ -1,41 +1,90 @@
1
- # Vinber
1
+ ## Vinber ##
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/vinber`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Vinber works for Rails, provides other way enumeration style which without force format output and force method definations.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ __NOTE__: Vinber current version *require* Ruby v1.9.0 or later and just tested on Rails 4.x for now .
6
6
 
7
- ## Installation
8
7
 
9
- Add this line to your application's Gemfile:
8
+ ### Installation ###
9
+ # Installing as Ruby gem
10
+ $ gem install vinber
11
+
12
+ # Or in gemfile
13
+ $ gem vinber
10
14
 
15
+ ### Usage ###
16
+
17
+ #### vinber
18
+ You will be able to use `vinber` in any model which inherit `ActiveRecord::Base`.
11
19
  ```ruby
12
- gem 'vinber'
20
+ vinber attribute: {} # hash
21
+ vinber attribute: [] # array
13
22
  ```
14
23
 
15
- And then execute:
24
+ ### vinber_list
25
+ `vinber_list` return a nested Array, it besides the attribute I18n value and vinber key.
26
+ ```ruby
27
+ vinber_list class_object, attribute
28
+ ```
16
29
 
17
- $ bundle
30
+ ### vinber_value
31
+ `vinber_value` return the I18n value of specific attribute.
18
32
 
19
- Or install it yourself as:
33
+ ```ruby
34
+ vinber_value instance_object, attribute
35
+ ```
20
36
 
21
- $ gem install vinber
37
+ ### Examples ###
38
+ Step 1, you need define your vinbers in your model.
39
+
40
+ ```ruby
41
+ # app/models/your_models.rb
42
+ class YourModel < ActiveRecord::Base
43
+ ...
22
44
 
23
- ## Usage
45
+ vinber :status => {:submited => 1, :processing => 2, :completed => 3}
24
46
 
25
- TODO: Write usage instructions here
47
+ ...
48
+ end
49
+ ```
26
50
 
27
- ## Development
51
+ Step 2, set your locale for I18n.
52
+ ```yaml
53
+ # config/locales/zh.yml or en.yml(any yml your want)
54
+ zh:
55
+ vinber:
56
+ YourModel:
57
+ status_submited: 提交
58
+ status_processing: 进行中
59
+ status_completed: 完成
28
60
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+ ```
30
62
 
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+ Step 3, invoking in view !! We assume you has YourModel and it contains records, the status of first record is `2`.
32
64
 
33
- ## Contributing
65
+ ```haml
66
+ # app/views/your_modles/index.haml
67
+ - obj = YourModel.first
68
+ %p= vinber_value(obj, :status)
34
69
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vinber. 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.
70
+ # => <p>进行中</p>
36
71
 
72
+ = form_tag({}) do
73
+ = select_tag "status", options_for_select(vinber_list YourModel, :status)
37
74
 
38
- ## License
75
+ # => <form accept-charset="UTF-8" method="post">
76
+ # => <select name="status" id="status">
77
+ # => <option value="1">提交</option>
78
+ # => <option value="2">进行中</option>
79
+ # => <option value="3">完成</option>
80
+ # => </select>
81
+ # => </form>
82
+ ```
39
83
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
84
+ ### TODO ###
85
+ - Write more clear document
86
+ - Add soft warning when error
87
+ - more functions
41
88
 
89
+ ### License ###
90
+ Released under the [MIT](http://opensource.org/licenses/MIT) license. See LICENSE file for details.
@@ -1,3 +1,3 @@
1
1
  module Vinber
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/vinber.rb CHANGED
@@ -1,5 +1,52 @@
1
- require "vinber/version"
1
+ require_relative 'vinber/version'
2
+ require_relative 'vinber/translate'
3
+ require_relative 'vinber/vinber_list'
4
+ require_relative 'vinber/vinber_value'
5
+ require_relative 'vinber/current_vinbers'
2
6
 
3
7
  module Vinber
4
- # Your code goes here...
8
+ class VinberUndefined < StandardError; end
9
+
10
+ def self.extended(base)
11
+ base.class_attribute(:defined_vinbers, instance_writer: false)
12
+ base.defined_vinbers = {}
13
+ end
14
+
15
+ def inherited(base)
16
+ base.defined_vinbers = defined_vinbers.deep_dup
17
+ super
18
+ end
19
+
20
+ def vinber(definitions)
21
+ definitions.each do |name, values|
22
+ defined_vinbers[name.to_s] = case
23
+ when values.is_a?(Hash)
24
+ values.with_indifferent_access
25
+ when values.is_a?(Array)
26
+ values
27
+ else
28
+ Array.wrap values.to_s
29
+ end
30
+ end
31
+ end
32
+
33
+ def vinbers
34
+ Vinber::CurrentVinbers.new defined_vinbers
35
+ end
36
+
37
+ def vinber_defined?(attr_key = nil)
38
+ attr_key ? defined_vinbers.has_key?(attr_key.to_s) : defined_vinbers.present?
39
+ end
5
40
  end
41
+
42
+ # Extend/Include to Rails
43
+ ActiveRecord::Base.extend Vinber
44
+ ActiveRecord::Base.extend Vinber::Value
45
+ ActiveRecord::Base.send(:include, Vinber::Value)
46
+
47
+ ApplicationHelper.extend Vinber::Value
48
+ ApplicationHelper.send(:include, Vinber::Value)
49
+ ApplicationHelper.send(:include, Vinber::List)
50
+
51
+ ApplicationController.extend Vinber::Value
52
+ ApplicationController.send(:include, Vinber::Value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vinber
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
  - cenxky