Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yash: ability to load config files through the magic of hashie :) #183

Closed
wants to merge 1 commit into from

Conversation

gregory
Copy link
Contributor

@gregory gregory commented Jul 4, 2014

Still need to update the changelog and readme... and squash :)

how you guys like it? cc @dblock

@dblock
Copy link
Member

dblock commented Jul 4, 2014

I love it.

I have some reservations about calling it "Fish", since that would be the first class that doesn't end with "ash". It could be called "Flash", especially that flash is a kind of storage. Another, possibly better name could be "Cash", for configuration. What do you think?

@gregory
Copy link
Contributor Author

gregory commented Jul 4, 2014

@dblock go for cash (config-hash) since it's more about config files than a storage system ... and we could keep flash for a futur usage.

what do i think? i love it of course :D i've update the changelog & readme.

@gregory gregory changed the title Fish: ability to load config files through the magic of hashie :) Cash: ability to load config files through the magic of hashie :) Jul 4, 2014
@bartoszkopinski
Copy link
Member

I'd be confused by Cash, that's a good name for a something related to money.

For a Yaml handling class I'd go for something like Yash maybe? A *.yml file doesn't have to be a config.

@gregory
Copy link
Contributor Author

gregory commented Jul 6, 2014

I don't mind the name. Yash sounds good to me too... @dblock or anyone reading this, should we go with Yash?

@bartoszkopinski
Copy link
Member

As a side note, I don't think I get the use of ['setting'] (should be "settings" I guess) in this example:

  #   if you have a config file like the following:
  #   #/etc/config/setting.yml
  #   development:
  #     foo: 'bar'
  #   production:
  #     foo: <%= ENV['FOO'] %> #let's say that ENV['FOO'] is set to 'BAR'
  #
  #   You can start cashing like this:
  #   config = Cash.new(folder_path: '/absolute_config_path')
  #   config['setting'].development # =>{ foo: 'bar' }
  • Mash is all about avoiding those brackets so I'd prefer config.settings.development instead, even in examples.
  • The param is called cash_alias_method, but that's not really an "alias method", is it? More like an additional namespace or reader accessor.
  • Could this be optional in a way that allows you to set no "alias" and use config.development.foo.bar directly? See Konf gem.

Just my thoughts, but anyways, very nice job!

B.

@gregory
Copy link
Contributor Author

gregory commented Jul 6, 2014

could be confusing, but the config['setting'](which should be settings:) is to access the setting.yml config file.
You feel like config.setting might be less confusing about what is happening?

cash_alias_method is indeed not an alias method, but the method you'll call to access your settings (by default: settings). any suggestion to rename that field?

The diff with the Konf gem, is that with one single module you can access any config file...

config = Cash.new(folder_path: '/absolute_config_path', namespace: 'production')
config['twitter'].api_key # => "api key for prod"
config['facebook'].client_id # => "facebook api key for prod"

Though i could do something like this:

twitter_config = Cash.new(folder_path: '/absolute_config_path', filename: 'twitter.yml', namespace: 'production')
twitter_config.api_key # => "Api key for prod"

@bartoszkopinski
Copy link
Member

Thanks for clearing that up. I get the difference now.
Well it's fine with me, just maybe add it to the Readme so it's clear that "setting" is a filename and "settings" is a default alias method for extending.

As for proposed future changes:

  • I'd stick with methods instead of brackets for consistency with Mash.
  • For a single file you can always detect it and handle both cases
Yash.new('/path', :production)
Yash.new('/path/config.yml', :production)

@dblock
Copy link
Member

dblock commented Jul 6, 2014

Ok, I think @bartoszkopinski is right regarding the naming, I'm down with Yash. I also do think the syntax of new above follows the rule of least surprise. It also makes Yash's default behavior very specific for YAML configuration files, which I think is good. I'll review the rest inline.

```ruby

# if you have a config file like the following:
# #/etc/config/setting.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would rename this to settings as suggested. Or maybe give it a completely different name, like database, just for illustration purposes and borrow variable names from a typical database configuration, like say host and port instead of foo.

@dblock
Copy link
Member

dblock commented Jul 6, 2014

Thanks for being patient on this @gregory. I think we have an opportunity to build the best YAML settings reader here, so lets try to get this right :)

@gregory
Copy link
Contributor Author

gregory commented Jul 7, 2014

doing a little refacto, will push when i'm done

@gregory
Copy link
Contributor Author

gregory commented Jul 7, 2014

@dblock & @bartoszkopinski i made some big changes on my vision of this. check the readme and let me know what you guys think about it! (personally , i love this new approach!)

@dblock dblock mentioned this pull request Jul 7, 2014
@@ -1,5 +1,5 @@
## Next

* [#183](https://github.com/intridea/hashie/pull/183) Added Cash, the ability to load config files - [@gregory](https://github.com/gregory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should say Yash.

@dblock
Copy link
Member

dblock commented Jul 7, 2014

I love how this implementation has evolved, see my comments above.

@gregory gregory changed the title Cash: ability to load config files through the magic of hashie :) Yash: ability to load config files through the magic of hashie :) Jul 7, 2014
@gregory
Copy link
Contributor Author

gregory commented Jul 8, 2014

@dblock what do you think about this?

@dblock
Copy link
Member

dblock commented Jul 9, 2014

I think I like.

@gregory
Copy link
Contributor Author

gregory commented Jul 10, 2014

ready for review and merge @dblock ;)

```

```ruby
mash = Mash.load('data/user.csv', MyCustomCsvParser)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a hash, parser: MyCustomCsvParser to enable future options or passing random options to passers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think that's what's implemented, just a doc bug.

we can now become a fisher by extending a fish :)

include pretty inspect... because it's pretty

add doc

fish is now cash

add todo

update changelog and readme

cash -> yash

format will always be yml

folder_path is a required param

set default namespace through class variable

better method names for less confusion

add ability to load specific yml file

load file from yash and improve extend

better spec and rename alias method

cleaner API, better specs

re write the doc and small bring namespace to the file_to_mash

update readme

simplify the code

move all the logic to mash + update logic

update changelog and readme
@gregory
Copy link
Contributor Author

gregory commented Jul 13, 2014

@dblock updated ;)

@dblock
Copy link
Member

dblock commented Jul 14, 2014

Rebased and merged via 59069f1.

@dblock dblock closed this Jul 14, 2014
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Feb 6, 2015
## 3.4.0 (02/02/2014)

* [#271](hashie/hashie#271): Added ability to define defaults based on current hash - [@gregory](https://github.com/gregory).
* [#247](hashie/hashie#247): Fixed #stringify_keys and #symbolize_keys collision with ActiveSupport - [@bartoszkopinski](https://github.com/bartoszkopinski).
* [#249](hashie/hashie#249): SafeAssignment will now also protect hash-style assignments - [@jrochkind](https://github.com/jrochkind).
* [#251](hashie/hashie#251): Added block support to indifferent access #fetch - [@jgraichen](https://github.com/jgraichen).
* [#252](https://github.com/intridia/hashie/pull/252): Added support for conditionally required Hashie::Dash attributes - [@ccashwell](https://github.com/ccashwell).
* [#256](https://github.com/intridia/hashie/pull/256): Inherit key coercions - [@Erol](https://github.com/Erol).
* [#259](https://github.com/intridia/hashie/pull/259): Fixed handling of default proc values in Mash - [@Erol](https://github.com/Erol).
* [#260](https://github.com/intridia/hashie/pull/260): Added block support to Extensions::DeepMerge - [@Galathius](https://github.com/galathius).
* [#254](hashie/hashie#254): Added public utility methods for stringify and symbolize keys - [@maxlinc](https://github.com/maxlinc).
* [#261](hashie/hashie#261): Fixed bug where Dash.property modifies argument object - [@d_tw](https://github.com/d_tw).
* [#264](hashie/hashie#264): Methods such as abc? return true/false with Hashie::Extensions::MethodReader - [@Zloy](https://github.com/Zloy).
* [#269](hashie/hashie#269): Add #extractable_options? so ActiveSupport Array#extract_options! can extract it - [@ridiculous](https://github.com/ridiculous).
* Your contribution here.

## 3.3.2 (11/26/2014)

* [#233](hashie/hashie#233): Custom error messages for required properties in Hashie::Dash subclasses - [@Joss](https://github.com/joss).
* [#231](hashie/hashie#231): Added support for coercion on class type that inherit from Hash - [@gregory](https://github.com/gregory).
* [#228](hashie/hashie#228): Made Hashie::Extensions::Parsers::YamlErbParser pass template filename to ERB - [@jperville](https://github.com/jperville).
* [#224](hashie/hashie#224): Merging Hashie::Mash now correctly only calls the block on duplicate values - [@amysutedja](https://github.com/amysutedja).
* [#221](hashie/hashie#221): Reduce amount of allocated objects on calls with suffixes in Hashie::Mash - [@kubum](https://github.com/kubum).
* [#245](hashie/hashie#245): Added Hashie::Extensions::MethodAccessWithOverride to autoloads - [@Fritzinger](https://github.com/Fritzinger).

## 3.3.1 (8/26/2014)

* [#183](hashie/hashie#183): Added Mash#load with YAML file support - [@gregory](https://github.com/gregory).
* [#195](hashie/hashie#195): Ensure that the same object is returned after injecting IndifferentAccess - [@michaelherold](https://github.com/michaelherold).
* [#201](hashie/hashie#201): Hashie::Trash transforms can be inherited - [@FoboCasteR](https://github.com/fobocaster).
* [#189](hashie/hashie#189): Added Rash#fetch - [@medcat](https://github.com/medcat).
* [#200](hashie/hashie#200): Improved coercion: primitives and error handling - [@maxlinc](https://github.com/maxlinc).
* [#204](hashie/hashie#204): Added Hashie::Extensions::MethodOverridingWriter and Hashie::Extensions::MethodAccessWithOverride - [@michaelherold](https://github.com/michaelherold).
* [#205](http://github.com/intridea/hashie/pull/205): Added Hashie::Extensions::Mash::SafeAssignment - [@michaelherold](https://github.com/michaelherold).
* [#206](http://github.com/intridea/hashie/pull/206): Fixed stack overflow from repetitively including coercion in subclasses - [@michaelherold](https://github.com/michaelherold).
* [#207](http://github.com/intridea/hashie/pull/207): Fixed inheritance of transformations in Trash - [@FoboCasteR](https://github.com/fobocaster).
* [#209](http://github.com/intridea/hashie/pull/209): Added Hashie::Extensions::DeepFind - [@michaelherold](https://github.com/michaelherold).
* [#69](hashie/hashie#69): Fixed regression in assigning multiple properties in Hashie::Trash - [@michaelherold](https://github.com/michaelherold), [@einzige](https://github.com/einzige), [@dblock](https://github.com/dblock).

## 3.2.0 (7/10/2014)

* [#164](hashie/hashie#164), [#165](hashie/hashie#165), [#166](hashie/hashie#166): Fixed stack overflow when coercing mashes that contain ActiveSupport::HashWithIndifferentAccess values - [@numinit](https://github.com/numinit), [@kgrz](https://github.com/kgrz).
* [#177](hashie/hashie#177): Added support for coercing enumerables and collections - [@gregory](https://github.com/gregory).
* [#179](hashie/hashie#179): Mash#values_at will convert each key before doing the lookup - [@nahiluhmot](https://github.com/nahiluhmot).
* [#184](hashie/hashie#184): Allow ranges on Rash to match all Numeric types - [@medcat](https://github.com/medcat).
* [#187](hashie/hashie#187): Automatically require version - [@medcat](https://github.com/medcat).
* [#190](hashie/hashie#190): Fixed `coerce_key` with `from` Trash feature and Coercion extension - [@gregory](https://github.com/gregory).
* [#192](hashie/hashie#192): Fixed StringifyKeys#stringify_keys! to recursively stringify keys of embedded ::Hash types - [@dblock](https://github.com/dblock).

## 3.1.0 (6/25/2014)

* [#169](hashie/hashie#169): Hash#to_hash will also convert nested objects that implement to_hash - [@gregory](https://github.com/gregory).
* [#171](hashie/hashie#171): Include Trash and Dash class name when raising `NoMethodError` - [@gregory](https://github.com/gregory).
* [#172](hashie/hashie#172): Added Dash and Trash#update_attributes! - [@gregory](https://github.com/gregory).
* [#173](hashie/hashie#173): Auto include Dash::IndifferentAccess when IndiferentAccess is included in Dash - [@gregory](https://github.com/gregory).
* [#174](hashie/hashie#174): Fixed `from` and `transform_with` Trash features when IndifferentAccess is included - [@gregory](https://github.com/gregory).

## 3.0.0 (6/3/2014)

**Note:** This version introduces several backward incompatible API changes. See [UPGRADING](UPGRADING.md) for details.

* [#150](hashie/hashie#159): Handle nil intermediate object on deep fetch - [@stephenaument](https://github.com/stephenaument).
* [#146](hashie/hashie#146): Mash#respond_to? inconsistent with #method_missing and does not respond to #permitted? - [@dblock](https://github.com/dblock).
* [#152](hashie/hashie#152): Do not convert keys to String in Hashie::Dash and Hashie::Trash, use Hashie::Extensions::Dash::IndifferentAccess to achieve backward compatible behavior - [@dblock](https://github.com/dblock).
* [#152](hashie/hashie#152): Do not automatically stringify keys in Hashie::Hash#to_hash, pass `:stringify_keys` to achieve backward compatible behavior - [@dblock](https://github.com/dblock).
* [#148](hashie/hashie#148): Consolidated Hashie::Hash#stringify_keys implementation - [@dblock](https://github.com/dblock).
* [#149](hashie/hashie#149): Allow IgnoreUndeclared and DeepMerge to be used with undeclared properties - [@jhaesus](https://github.com/jhaesus).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants