Module: BSNS
- Included in:
- Base
- Defined in:
- lib/bsns.rb
Defined Under Namespace
Classes: Base
Constant Summary collapse
- @@config =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #acts_as_collection ⇒ Object
- #has_many(model, opts = {}) ⇒ Object
- #has_one(model, opts = {}) ⇒ Object
Class Method Details
.configure(opts) ⇒ Object
41 42 43 |
# File 'lib/bsns.rb', line 41 def self.configure opts @@config = opts end |
.get_config(key) ⇒ Object
45 46 47 |
# File 'lib/bsns.rb', line 45 def self.get_config key @@config[key.to_sym] end |
Instance Method Details
#acts_as_collection ⇒ Object
37 38 39 |
# File 'lib/bsns.rb', line 37 def acts_as_collection set_v :single_file, true end |
#has_many(model, opts = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bsns.rb', line 7 def has_many model, opts = {} field = opts[:as] || model.to_s.downcase.pluralize with = opts[:with] || nil = opts[:embedded] || false model = model.to_s.singularize class_eval do define_method field do obj_from_dataset instance_variable_get("@#{field}"), model, opts end end end |
#has_one(model, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bsns.rb', line 19 def has_one model, opts = {} model = model.to_s field = opts[:as] || model.downcase class_eval do define_method field do klass = model.capitalize.constantize.load data = instance_variable_get "@#{field}" if opts[:embedded] obj = klass.new data else if data.type_of? Hash obj = klass.load data[0] end end end end end |